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

False negative with a closure parameter to a method of a generic class #4782

Closed
weirdan opened this issue Dec 5, 2020 · 2 comments
Closed
Labels

Comments

@weirdan
Copy link
Collaborator

weirdan commented Dec 5, 2020

https://psalm.dev/r/99363f746a

I believe it should fail with

ERROR: InvalidScalarArgument - t.php:18:10 - Type string should be a subtype of int (see https://psalm.dev/012)
     $c->map(function(int $_p): bool { return (bool) rand(0,1); });

as it did before 4d81682

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/99363f746a
<?php
/**
 * @template TKey
 * @template TValue
 */
interface Collection {
    /**
     * @template T
     * @param Closure(TValue=):T $func
     * @return Collection<TKey,T>
     */
    public function map(Closure $func);

}

/** @param Collection<int,string> $c */
function f(Collection $c): void {
     $c->map(function(int $_p): bool { return (bool) rand(0,1); });
}
Psalm output (using commit 3f15579):

No issues!

@weirdan weirdan added the bug label Dec 5, 2020
@weirdan
Copy link
Collaborator Author

weirdan commented Dec 5, 2020

> cat > t.php <<'EOM'
<?php
/**
 * @template TKey
 * @template TValue
 */
interface Collection {
    /**
     * @template T
     * @param Closure(TValue=):T $func
     * @return Collection<TKey,T>
     */
    public function map(Closure $func);

}

/** @param Collection<int,string> $c */
function f(Collection $c): void {
     $c->map(function(int $_p): bool { return (bool) rand(0,1); });
}
EOM

> git bisect good 4.0.0
> git bisect bad master
> git bisect run bash -c '! ./psalm t.php'
......
4d81682fdd3132906ca4781a4c9f05163955ac0d is the first bad commit
......

@muglug muglug closed this as completed in cec8d71 Dec 5, 2020
danog pushed a commit to danog/psalm that referenced this issue Jan 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant