Conversation
- Fixed getCoalesceType() in MutatingScope to avoid over-narrowing the right
side of ?? when conditional expressions from scope merging make correlated
variables all null together
- The fix uses the narrowed scope only when it successfully removes null from
the right type (useful for `if ($a || $b) { $a ?? $b }` patterns), and
falls back to the unfiltered type otherwise
- New regression test in tests/PHPStan/Analyser/nsrt/bug-14213.php
Closes phpstan/phpstan#14213
|
this PR fixes the type-inference part, but does not fix the "Variable $x1 on left side of ?? always exists and is always null." error. I would open a new issue after this one merged and would let the bot give another try on fixing this error. (and initially I tried this examples because I want to see slow analysis of COALESCE similar to what we saw with AND - wich I found and will be another followup after this blocker is out of the way) |
|
I feel like there is no issue to fix The message is not clear but when the variable x0 is null it's true that the variable x1 is always null too ! So it's useless to write x0 ?? x1 And the inference was right to me too, it's int<0, 1>|null because the variable x1 and x2 are not null only when the variable x0 is not null, so we cannot reach those values |
|
ohh my you are right. I am dumb - adjusted the PR to just add tests |
|
thank you |
covers coalesce with int ranges in tests