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

Array shapes are lost in a typehinted closure #4083

Closed
ramonacat opened this issue Nov 13, 2020 · 3 comments
Closed

Array shapes are lost in a typehinted closure #4083

ramonacat opened this issue Nov 13, 2020 · 3 comments

Comments

@ramonacat
Copy link

Bug report

When a closure has an array typehint, PHPStan does not recognize the shape of the array, even if it's able to do so when the typehint is not present.

Code snippet that reproduces the problem

https://phpstan.org/r/38829cd6-d8d5-4603-b07c-5f79335e0ce2

Expected output

No errors.

@phpstan-bot
Copy link
Contributor

@Agares After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-PHP 7.4 – 8.0 (1 error)
+PHP 7.4 – 8.0
 ==========
 
-8: Parameter #1 $x of method HelloWorld::takesShapedArray() expects array(int, string), array given.
+No errors
 
 PHP 7.1 – 7.3 (4 errors)
 ==========
Full report

PHP 7.4 – 8.0

No errors

PHP 7.1 – 7.3 (4 errors)

Line Error
8 Syntax error, unexpected ',' on line 8
8 Syntax error, unexpected T_VARIABLE, expecting ':' on line 8
9 Syntax error, unexpected ',' on line 9
9 Syntax error, unexpected T_DOUBLE_ARROW, expecting ')' on line 9

@ramonacat
Copy link
Author

Nice, it appears that this now works correctly 💪

ondrejmirtes added a commit to phpstan/phpstan-src that referenced this issue Jun 26, 2021
@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants