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
False positive: Offset ... on array... on left side of ?? always exists and is not nullable. #5933
Comments
Not sure if same usecase, but same error: |
@schlndh PHPStan is smart and I think that it knows what's going on in your example: https://phpstan.org/r/1b680ac5-e330-47e7-bc0e-132f83f31588 - the @chaos0815 unrelated, please open a separate issue. |
@ondrejmirtes Thanks, but I don't understand your explanation. Clearly, it can happen that Of course, I understand that an array structure can be arbitrarily complex and PHPStan can never understand everything. In this case, I'd say that Ultimately, it's probably best not to write code like this in the first place and use proper types instead. 😅 |
I'm sorry, I misread the example, I thought that in both if/else |
@schlndh After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-18: Offset 'a' on array{a: int<min, 99>, b: int<min, 99>} on left side of ?? always exists and is not nullable.
+18: Offset 'a' on array{a: int<0, 99>, b: int<0, 99>} on left side of ?? always exists and is not nullable. Full report
|
@schlndh After the latest commit in 1.6.x, PHPStan now reports different result with your code snippet: @@ @@
-18: Offset 'a' on array{a: int<min, 99>, b: int<min, 99>} on left side of ?? always exists and is not nullable.
+No errors |
@ondrejmirtes After the latest commit in 1.6.x, PHPStan now reports different result with your code snippet: @@ @@
-17: Dumped type: non-empty-array<int<0, 99>, array{a: int<0, 99>, b: int<0, 99>}>
-20: Offset 'a' on array{a: int<0, 99>, b: int<0, 99>} on left side of ?? always exists and is not nullable.
+17: Dumped type: non-empty-array<int<0, 99>, array{a?: int<0, 99>, b?: int<0, 99>}&non-empty-array> Full report
|
Closes phpstan/phpstan#6383 Closes phpstan/phpstan#5933 Closes phpstan/phpstan#5382 Closes phpstan/phpstan#6379 Closes phpstan/phpstan#3284
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
Phpstan gets confused when an associative array is created in a loop and subsequently the array is foreach-ed over. It thinks that all the offsets that may have been assigned are assigned and it complains about
?? null
. It's one of the new errors that I saw after upgrading to 1.0, so it's probably a regression (unless the message changed and wasn't caught by the baseline anymore).Code snippet that reproduces the problem
https://phpstan.org/r/1420808b-7d48-41c2-936e-8e17b0bdae94
Expected output
It shouldn't complain about
?? null
.The text was updated successfully, but these errors were encountered: