-
-
Notifications
You must be signed in to change notification settings - Fork 947
Narrowing tagged unions based on count is broken without array shape sealness implemented first #11494
Copy link
Copy link
Open
Labels
Description
Bug report
phpstan/phpstan-src#3302 has implemented narrowing based on the count of items in an array. But this relies on treating the shaped as sealed while analyzing valid method arguments treats all values as unsealed. This makes the static analysis mismatch with the runtime behavior of the code, making issues go undetected.
Code snippet that reproduces the problem
https://phpstan.org/r/6152adda-09b3-4920-8152-06be18efcd18
Expected output
There is 2 valid output for that:
- Reporting an error about accessing
shortand reporting an error about passing theextrakey when calling the function. This is the behavior when treating the shape as sealed - Reporting an error when accessing
detailsas it might not always be defined in the union (behavior for unsealed shapes)
See https://3v4l.org/v7boM for the execution of that code snippet, showing that it fails on line 12, where phpstan currently does not report any issue (in scenario 2, an error would be reported on line 12, while scenario 1 would report it on line 16, which is the previous frame in the stack trace of the warning).
Did PHPStan help you today? Did it make you happy in any way?
No response
Reactions are currently unavailable