You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When an array contains a generic value at a known index, and then another value is conditionally added (e.g. only if something is non-empty), the type of the first value gets lost. See snippet + expected output for details.
Note that I have the attached template declared as @template-covariant but the issue doesn't seem specific to that.
No errors (other than the dumpType() results added to step through the error).
The dumped type on lines 36 and 39 are both correct; observe that the type at the result index changes on line 41, which is incorrect and causes the complaint on the return value.
Also, I've observed that restructuring this to add resultaftererrors does not exhibit this issue. Similarly, not adding errors conditionally behaves as expected from a typechecker perspective (though not what I need at runtime).
Did PHPStan help you today? Did it make you happy in any way?
PHPStan makes me develop faster and more accurately every day!
The text was updated successfully, but these errors were encountered:
Bug report
When an array contains a generic value at a known index, and then another value is conditionally added (e.g. only if something is non-empty), the type of the first value gets lost. See snippet + expected output for details.
Note that I have the attached template declared as
@template-covariant
but the issue doesn't seem specific to that.Code snippet that reproduces the problem
https://phpstan.org/r/f508e2b7-f6f9-4919-8502-cd1a1cdd105a
Expected output
No errors (other than the
dumpType()
results added to step through the error).The dumped type on lines 36 and 39 are both correct; observe that the type at the
result
index changes on line 41, which is incorrect and causes the complaint on the return value.Also, I've observed that restructuring this to add
result
aftererrors
does not exhibit this issue. Similarly, not addingerrors
conditionally behaves as expected from a typechecker perspective (though not what I need at runtime).Did PHPStan help you today? Did it make you happy in any way?
PHPStan makes me develop faster and more accurately every day!
The text was updated successfully, but these errors were encountered: