-
Notifications
You must be signed in to change notification settings - Fork 672
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 type assertion for Arithemtic addition and subtraction #11269
Fix type assertion for Arithemtic addition and subtraction #11269
Conversation
…nus is performed in the context of an assignment
Cool! Seems like an improvement but I'm not sure it fixes everything Can you check this for example? https://psalm.dev/r/6f97b61d3d What you did is replace We should fix it here if we can I think we need to check what's in |
I found these snippets: https://psalm.dev/r/6f97b61d3d<?php
/** @return int<0,5> */
function intFunc(): int {
return 5;
}
$a = 1;
$a += intFunc();
/** @psalm-trace $a */;
|
I can't really seem to reproduce the sum issues in other situations. The example you sent with an int-range is handled in an earlier branch. Same with additions/subtractions that have an TLiteralInt on the right side, and are not inside of a loop. If i check the right type part, and grab that value if it is a // Replacing the sum assignment with this:
if ($right_type_part instanceof TLiteralInt) {
$sum = $right_type_part->value;
} else {
$sum = $parent instanceof VirtualPlus ? 1 : -1;
} Causes the
Increments in loops also seem to be the only situation where the righthand side is a TLiteralInt from what i can see in the tests present. Edit: typo |
Fair enough! Can you just leave a comment above the $sum initialisation with something like "This seems arbitrary defined as 1/-1, this may need a better handling if there's issues" Just to facilitate a future debugging :p Thanks! |
Thanks! |
Closes #11241