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
Psalm fails to narrow type to positive int inside loop #8865
Comments
I found these snippets: https://psalm.dev/r/155977bb20<?php
function sleepLoop(float $seconds, int $repeat): void
{
$microseconds = (int) ($seconds * 1_000_000);
for ($i = 0; $i < $repeat; $i++) {
if ($microseconds > 0) {
usleep($microseconds);
}
}
}
sleepLoop(1.5, 5);
|
theodorejb
changed the title
Incorrect type inference inside loop
Psalm fails to narrow type to positive int inside loop
Dec 9, 2022
Note: this worked as expected in Psalm 4.x, so it's a regression in Psalm 5. |
theodorejb
added a commit
to theodorejb/psalm
that referenced
this issue
Dec 18, 2022
theodorejb
added a commit
to theodorejb/psalm
that referenced
this issue
Dec 18, 2022
theodorejb
added a commit
to theodorejb/psalm
that referenced
this issue
Dec 18, 2022
Note: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Psalm fails to infer that a variable is a positive int when the condition occurs inside a loop.
https://psalm.dev/r/155977bb20
The text was updated successfully, but these errors were encountered: