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
5.4: Issue with flow analysis causes NoValue false positive #8952
Comments
I found these snippets: https://psalm.dev/r/8a407af77c<?php
$v = 0;
do {
$foo = "a";
if ($v > 0) {
$foo .= sprintf('_%02d', $v);
}
$v++;
} while (rand(1,10) < 5);
echo $foo;
|
Encountered this too when making a PR, possibly caused by #8934 The issue is that the if statement is analyzed twice, once with the impossible values inferred on the first iteration (always |
I found these snippets: https://psalm.dev/r/3b6e234333<?php
$v = 0;
do {
$foo = "a";
if ($v > 0) {
/** @psalm-trace $v */;
$foo .= sprintf('_%02d', $v);
}
$v++;
} while (rand(1,10) < 5);
echo $foo;
|
in my case, the workaround is to put the increment before the if and change the condition to |
Yeah, in the case of https://psalm.dev/r/b33c14eaf6 there should be a paradox since Overall I think the current behavior for https://psalm.dev/r/8a407af77c is correct, as it detects that there might be an impossible code path at some point in the iteration, closing this unless someone else comes up with a more broken example. |
I found these snippets: https://psalm.dev/r/b33c14eaf6<?php
$v = 0;
do {
$foo = "a";
$v++;
/** @psalm-trace $v */;
if ($v > 0) {
$foo .= sprintf('_%02d', $v);
}
} while (rand(1,10) < 5);
echo $foo;
https://psalm.dev/r/8a407af77c<?php
$v = 0;
do {
$foo = "a";
if ($v > 0) {
$foo .= sprintf('_%02d', $v);
}
$v++;
} while (rand(1,10) < 5);
echo $foo;
|
cc @orklah just in case you want to comment on this too |
I agree with that, so it seems there is indeed a bug here. I would keep this open? Unless I missed something? |
I found these snippets: https://psalm.dev/r/3b6e234333<?php
$v = 0;
do {
$foo = "a";
if ($v > 0) {
/** @psalm-trace $v */;
$foo .= sprintf('_%02d', $v);
}
$v++;
} while (rand(1,10) < 5);
echo $foo;
|
https://psalm.dev/r/8a407af77c
psalm seems to get confused that
$v
is updated in the loop after the condition.This was fine in 5.3 and prior and is broken in 5.4
The text was updated successfully, but these errors were encountered: