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 not properly checked when appending arrays #6356

Open
phinor opened this issue Jan 13, 2022 · 5 comments · Fixed by phpstan/phpstan-src#1748
Open

Array shapes are not properly checked when appending arrays #6356

phinor opened this issue Jan 13, 2022 · 5 comments · Fixed by phpstan/phpstan-src#1748
Labels
Milestone

Comments

@phinor
Copy link

phinor commented Jan 13, 2022

Bug report

When appending records to an array, the array shapes are not checked / reported properly.

Code snippet that reproduces the problem

https://phpstan.org/r/871e400d-6df0-4cc0-91a6-3b9c5798b987

Expected output

Line 25 does not produce an error (and I believe it should), but this error seemingly is reported on line 27 which should not generate an error.

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Jan 14, 2022
@phpstan-bot
Copy link
Contributor

@phinor After the latest commit in 1.6.x, PHPStan now reports different result with your code snippet:

@@ @@
 17: Property HelloWorld::$details (array{name: string, age: int}) does not accept array{name: string, age: 'Forty-two'}.
 19: Property HelloWorld::$nestedDetails (array<array{name: string, age: int}>) does not accept non-empty-array<array{name: string, age: 'Eleventy-one'|int}>.
 24: Property HelloWorld::$nestedDetails (array<array{name: string, age: int}>) does not accept non-empty-array<array{name: string, age: 'Twelve'|int}>.
-27: Property HelloWorld::$nestedDetails (array<array{name: string, age: int}>) does not accept non-empty-array<array{name: string, age: 'Five'|int}>.
+27: Property HelloWorld::$nestedDetails (array<array{name: string, age: int}>) does not accept non-empty-array<array{age: 'Five'|int, name: string}>.
Full report
Line Error
17 Property HelloWorld::$details (array{name: string, age: int}) does not accept array{name: string, age: 'Forty-two'}.
19 `Property HelloWorld::$nestedDetails (array<array{name: string, age: int}>) does not accept non-empty-array<array{name: string, age: 'Eleventy-one'
24 `Property HelloWorld::$nestedDetails (array<array{name: string, age: int}>) does not accept non-empty-array<array{name: string, age: 'Twelve'
27 `Property HelloWorld::$nestedDetails (array<array{name: string, age: int}>) does not accept non-empty-array<array{age: 'Five'

@allejo
Copy link
Contributor

allejo commented Apr 5, 2022

Another code snippet that replicates this issue: https://phpstan.org/r/ecb4ac1d-91f9-4522-9631-23ce4ed3e310

@phpstan-bot
Copy link
Contributor

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

@@ @@
 17: Property HelloWorld::$details (array{name: string, age: int}) does not accept array{name: string, age: 'Forty-two'}.
 19: Property HelloWorld::$nestedDetails (array<array{name: string, age: int}>) does not accept non-empty-array<array{name: string, age: 'Eleventy-one'|int}>.
-24: Property HelloWorld::$nestedDetails (array<array{name: string, age: int}>) does not accept non-empty-array<array{name: string, age: 'Twelve'|int}>.
-27: Property HelloWorld::$nestedDetails (array<array{name: string, age: int}>) does not accept non-empty-array<array{name: string, age: 'Five'|int}>.
+24: Property HelloWorld::$nestedDetails (array<array{name: string, age: int}>) does not accept non-empty-array<array{name: string, age: 'Twelve'|int}>.
Full report
Line Error
17 Property HelloWorld::$details (array{name: string, age: int}) does not accept array{name: string, age: 'Forty-two'}.
19 `Property HelloWorld::$nestedDetails (array<array{name: string, age: int}>) does not accept non-empty-array<array{name: string, age: 'Eleventy-one'
24 `Property HelloWorld::$nestedDetails (array<array{name: string, age: int}>) does not accept non-empty-array<array{name: string, age: 'Twelve'

@phpstan-bot
Copy link
Contributor

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

@@ @@
 17: Property HelloWorld::$details (array{name: string, age: int}) does not accept array{name: string, age: 'Forty-two'}.
-19: Property HelloWorld::$nestedDetails (array<array{name: string, age: int}>) does not accept non-empty-array<array{name: string, age: 'Eleventy-one'|int}>.
-24: Property HelloWorld::$nestedDetails (array<array{name: string, age: int}>) does not accept non-empty-array<array{name: string, age: 'Twelve'|int}>.
-27: Property HelloWorld::$nestedDetails (array<array{name: string, age: int}>) does not accept non-empty-array<array{name: string, age: 'Five'|int}>.
+19: Property HelloWorld::$nestedDetails (array<array{name: string, age: int}>) does not accept non-empty-array<array{name: 'Bilbo Baggins', age: 'Eleventy-one'}|array{name: string, age: int}>.
+24: Property HelloWorld::$nestedDetails (array<array{name: string, age: int}>) does not accept non-empty-array<array{name: string, age: 'Twelve'}|array{name: string, age: int}>.
Full report
Line Error
17 Property HelloWorld::$details (array{name: string, age: int}) does not accept array{name: string, age: 'Forty-two'}.
19 `Property HelloWorld::$nestedDetails (array<array{name: string, age: int}>) does not accept non-empty-array<array{name: 'Bilbo Baggins', age: 'Eleventy-one'}
24 `Property HelloWorld::$nestedDetails (array<array{name: string, age: int}>) does not accept non-empty-array<array{name: string, age: 'Twelve'}

@phpstan-bot
Copy link
Contributor

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

@@ @@
-17: Property HelloWorld::$lists (array<0|1|2|3, array<int, bool>>) does not accept non-empty-array<int<0, 3>, array<int, bool>>.
+No errors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants