Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function with conditional types gives errors since 4.7.0 #5506

Closed
Etherlord opened this issue Mar 29, 2021 · 2 comments
Closed

Function with conditional types gives errors since 4.7.0 #5506

Etherlord opened this issue Mar 29, 2021 · 2 comments

Comments

@Etherlord
Copy link

#5198 This bug is reproduced again since 4.7.0

https://psalm.dev/r/9449b708b5

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/9449b708b5
<?php

/**
 * @psalm-pure
 * @template TValue
 * @template TIterable of ?iterable<TValue>
 * @param TIterable $iterable
 * @return (TIterable is null ? null : list<TValue>)
 */
function toList(?iterable $iterable): ?array
{
    if (null === $iterable) {
        return null;
    }

    if (is_array($iterable)) {
        return array_values($iterable);
    }

    return iterator_to_array($iterable, false);
}
Psalm output (using commit d57dde0):

INFO: MixedReturnTypeCoercion - 17:16 - The type 'array<array-key, mixed>' is more general than the declared return type '(list<TValue:fn-tolist as mixed>)|null' for toList

INFO: MixedReturnTypeCoercion - 20:12 - The type 'array<array-key, mixed>' is more general than the declared return type '(list<TValue:fn-tolist as mixed>)|null' for toList

INFO: MixedReturnTypeCoercion - 8:12 - The declared return type '(list<TValue:fn-tolist as mixed>)|null' for toList is more specific than the inferred return type 'array<array-key, mixed>|null'

@muglug
Copy link
Collaborator

muglug commented Mar 29, 2021

It's not since 4.7.0 – it's been an issue for a while, after an earlier commit fixed a false negative.

@muglug muglug closed this as completed in 17e1479 Mar 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants