vimeo / psalm

A static analysis tool for finding errors in PHP applications
https://psalm.dev
MIT License
5.54k stars 660 forks source link

Iterating over WeakMap forgets generic types #10220

Open seyfahni opened 12 months ago

seyfahni commented 12 months ago

Expected behavior: When iterating over a WeakMap keys have the type set via generic definition inferred.

Actual behavior: When iterating over a WeakMap keys have the mixed type.

https://psalm.dev/r/09953666a9

psalm-github-bot[bot] commented 12 months ago

I found these snippets:

https://psalm.dev/r/09953666a9 ```php */ $map = new WeakMap(); foreach ($map as $action => $_) { $action->execute(); } ``` ``` Psalm output (using commit 7428e49): INFO: MixedAssignment - 13:18 - Unable to determine the type that $action is being assigned to INFO: MixedMethodCall - 14:14 - Cannot determine the type of $action when calling method execute ```
robchett commented 11 months ago

Appears this a regression, bisect isolates this commit https://github.com/vimeo/psalm/commit/70319a68a7696105384759252bc55810c0c197e1, specifically composer.json

There is a test for this, which runs fine in PHPUnit, but that runs in 7.4 mode, the issue only occurs when run in a project with a minimum version of 8.0.

@weirdan, anything jump out at you why a version change would stop that class stub working? The only thing that I could see was the @since 8.0.0 but removing that didn't fix the test.