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
Wrong inference about array from PHPStan #8087
Comments
https://phpstan.org/r/4b292f19-c957-4967-89b6-31cdc3b31529 dumped type should be
and not
|
The code started to fail with this commit: phpstan/phpstan-src@8f44183 I'm not sure I can do more to help |
You marked this as easy fix. Any recommendation about how solving this @ondrejmirtes ? |
Just guessing, but I'd closely look at the array_unique. There's an extension that specifies the arg as non-empty-array and maybe that's done incorrectly. E.g. maybe isIterableAtLeastOnce incorrectly returns yes or it needs an additional check to ensure it's an iterable/array or the offset exists for sure or so. The type for data['uses'] changes from mixed to non-empty-array because of it and that must be related somehow |
Not sure it's related to array_unique since I can reproduce this without it Or even https://phpstan.org/r/8ed2fee6-9069-448e-bc4a-cd09aeffe784 |
If you play around with your last example, which you surely did already I suppose, you see that the ArrayDimFetch append statement is most likely related, see https://phpstan.org/r/921492b3-3535-419e-8e25-8e13fee8bf1d |
I debugged a little, issue is here: here, I try to override the array with a wrong value the value is computed here: the issue is with the call
it's done on an IntersectionType. The new type is computed in ArrayType::setOffsetValueType then. The call is made on
This is because Then, I can fix my personal issue this way phpstan/phpstan-src#1808 Maybe this code is talking to you... Do you have any recommendation @herndlm ? |
Seems like the
But this seems to be a little buggy because we also have the following test passing
which is not true. But I have difficulties to understand how should I fix this. For the record, psalm (https://psalm.dev/r/7f28c720dd) consider it's
which is not true either but is the same that I have with the change phpstan/phpstan-src#1808. I'm not sure how hard it is to differentiate
and
But to me it would be ok having a less precise array shape, and promote instead to write code like this |
phpstan/phpstan-src@600e9e1 Fix issue #8087 phpstan/phpstan-src@bfcef68 Merge remote-tracking branch 'origin/1.8.x' into 1.9.x
@VincentLanglet After the latest push in 1.9.x, PHPStan now reports different result with your code snippet: @@ @@
-13: Comparison operation ">" between int<1, max> and 0 is always true.
+No errors |
@VincentLanglet After the latest push in 1.9.x, PHPStan now reports different result with your code snippet: @@ @@
10: Dumped type: array<string, mixed>
-15: Dumped type: non-empty-array<string, non-empty-array>&hasOffsetValue('uses', non-empty-array)
-17: Comparison operation ">" between int<1, max> and 0 is always true.
+15: Dumped type: non-empty-array<string, mixed>&hasOffsetValue('uses', non-empty-array) Full report
|
@VincentLanglet After the latest push in 1.9.x, PHPStan now reports different result with your code snippet: @@ @@
10: Dumped type: array<string, mixed>
-15: Dumped type: non-empty-array<string, non-empty-array<''>>&hasOffsetValue('uses', non-empty-array<''>)
-17: Comparison operation ">" between int<1, max> and 0 is always true.
+15: Dumped type: non-empty-array<string, mixed>&hasOffsetValue('uses', non-empty-array<''>) Full report
|
@VincentLanglet After the latest push in 1.9.x, PHPStan now reports different result with your code snippet: @@ @@
10: Dumped type: array<string, mixed>
-15: Dumped type: non-empty-array<string, array{'', ''}>&hasOffsetValue('uses', array{'', ''})
-17: Comparison operation ">" between 2 and 0 is always true.
+15: Dumped type: non-empty-array<string, mixed>&hasOffsetValue('uses', array{'', ''}) Full report
|
Fixed by phpstan/phpstan-src#1808 |
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. |
Bug report
I suspect that some optimisation about array is creating an issue
@ondrejmirtes @rvanvelzen
Code snippet that reproduces the problem
https://phpstan.org/r/7aacecc5-cd35-4ec4-98ae-c70b4635e1ef
Doing things on one key of the array is automatically changing the way phpstan is inferring the other key (and the whole array).
Expected output
No errors.
The text was updated successfully, but these errors were encountered: