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
Wrong TypeDoesNotContainNull determination #9894
Labels
Comments
I found these snippets: https://psalm.dev/r/74b5ec5ba5<?php
function getFoo(): ?int {
return rand(0, 1) === 1 ? 1 : null;
}
function test(?stdClass $existing = null): void {
$foo = getFoo();
$bar = getFoo();
/** @psalm-trace $existing */;
if ($foo !== null) {
assert($foo === 1);
} elseif ($existing === null) {
throw new \RuntimeException('foo');
}
/** @psalm-trace $existing */;
if ($bar !== null) {
assert($bar === 1);
} elseif ($existing === null) {
throw new \RuntimeException('bar');
}
}
test(null);
|
If the |
I found these snippets: https://psalm.dev/r/d274855806<?php
function getFoo(): ?int {
return rand(0, 1) === 1 ? 1 : null;
}
function test(?stdClass $existing = null): void {
$foo = getFoo();
$bar = getFoo();
/** @psalm-trace $existing */;
if ($foo !== null) {
assert($foo === 1);
} else {
if ($existing === null) {
throw new \RuntimeException('foo');
}
}
/** @psalm-trace $existing */;
if ($bar !== null) {
assert($bar === 1);
} elseif ($existing === null) {
throw new \RuntimeException('bar');
}
}
test(null);
|
Is this issue still relevant? It looks like it was fixed. |
I believe this is fixed in #9922 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, I have found also another case where Psalm thinks that in the example the
$existing
variable does not containnull
s.https://psalm.dev/r/74b5ec5ba5
But it could be
null
in case$foo
is1
and$bar
isnull
. It looks like Psalm does not recognize theelseif
and thinks that there is a standaloneif
which would indeed remove thenull
type.Maybe this is also related to #7099
The text was updated successfully, but these errors were encountered: