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 shape comparing doesn't work properly when narrowed from mixed #7156

Closed
fluffycondor opened this issue Apr 29, 2022 · 4 comments
Closed

Comments

@fluffycondor
Copy link
Contributor

Bug report

PHPStan 1.6.2

If a variable is narrowed from mixed to a shaped array, PHPStan fails to compare it properly.
https://phpstan.org/r/8273475b-6e96-4e2d-baa0-7a0fea921fc0
The same code doesn't yield any errors if I just replace mixed with array:
https://phpstan.org/r/98b21779-1265-465e-ab65-0967bf6feb8f

Code snippet that reproduces the problem

https://phpstan.org/r/8273475b-6e96-4e2d-baa0-7a0fea921fc0

Expected output

No errors.

Did PHPStan help you today? Did it make you happy in any way?

❤️ ❤️ ❤️

@herndlm
Copy link
Contributor

herndlm commented May 5, 2022

This works if bleeding edge is not used. I wonder if my explicit mixed is_array changes are the reason :/ phpstan/phpstan-src#1191

@phpstan-bot
Copy link
Contributor

@fluffycondor After the latest push in 1.8.x, PHPStan now reports different result with your code snippet:

@@ @@
-16: Dumped type: array&hasOffset('value')
-18: Parameter #1 $foo of function foo expects array{value: string}, array given.
+16: Dumped type: array&hasOffsetValue('value', string)
Full report
Line Error
16 Dumped type: array&hasOffsetValue('value', string)

@phpstan-bot
Copy link
Contributor

@fluffycondor After the latest push in 1.8.x, PHPStan now reports different result with your code snippet:

@@ @@
-19: Dumped type: array&hasOffset('value')
+19: Dumped type: array&hasOffsetValue('value', string)
Full report
Line Error
19 Dumped type: array&hasOffsetValue('value', string)

@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 Aug 27, 2022
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

4 participants