-
Notifications
You must be signed in to change notification settings - Fork 651
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
Fix added null type after if #9468
Conversation
🤔 At first glance, this fix looks dubious to me, especially the fact that it touches the |
It makes some sense though. The issue seems definitely linked to reconciliation to me, not control flow. See snippet: https://psalm.dev/r/9432deb60a I'm not perfectly sure about the fix, especially the part where it exclude $this seems suspicious, but I think there's something correct in this |
I found these snippets: https://psalm.dev/r/9432deb60a<?php
$a = -1;
if ($a !== null) {
/** @psalm-trace $a */;
}
else {
/** @psalm-trace $a */;
}
/** @psalm-trace $a */;
echo $a;
|
If no assignments have been made to the variable in the You can also say that assertions for |
On second thought, it should be |
I don't know enough of condition reconciliation then. I thought we made a union between the branches in every case. |
That's why we track assigned/redefined vars in |
Psalm indeed seems to rely on the mutual cancellation because my 'fix' resulted in over 3.5K errors reported on Psalm's own codebase. But there's definitely also something wrong with the scope manipulation logic as well $a = 1;
if ($a !== null) {} evaluates a hypothetical Psalm also doesn't seem to treat hypothetical and real |
I believe #9538 is a better fix for that specific issue. |
Fixes #9395, but not #9348
Maybe the condition needs to be refined according to this:
psalm/src/Psalm/Internal/Type/AssertionReconciler.php
Lines 478 to 481 in 222887a
With a simple
else
instead ofelseif ($key !== '$this')
these three tests started to fail:Some helpful comments for debugging: 6638deb
As noted above, I'm very unsure about the correct condition needed here, but this seems to work with the current test base.