-
Notifications
You must be signed in to change notification settings - Fork 663
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
PossiblyNullPropertyFetch after check with nullsafe operator #5873
Comments
I found these snippets: https://psalm.dev/r/2d78032069<?php
class a
{
public ?b $b = null;
}
class b
{
public ?int $c = null;
}
function test(a $a): void
{
// This breaks...
if ($a->b?->c != null) {
echo $a->b->c;
}
// ...but is equivalent to this, right?
if ($a->b != null && $a->b->c != null) {
echo $a->b->c;
}
}
|
Experiencing the same. Here is a snippet:
This should be type-safe I guess? |
Another useful example: https://psalm.dev/r/86ffcdda1f |
I found these snippets: https://psalm.dev/r/86ffcdda1f<?php
function foo(): void {
/** @var object|null */
$foo = new stdClass();
if($foo?->bar === null) {
return;
}
/** @psalm-trace $foo */
}
|
@SCIF the two snippets still fail in the same way so this doesn't seem resolved |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://psalm.dev/r/2d78032069
I could be wrong, but it seems to me that if you check for not-null against something using a null safe operator, then it should validate the entire chain as not null, but that's not what happens.
For example
assert($a->b?->c?->d?->e != null)
should mean that a through e are all not null, correct? Otherwise the assert would fail.The text was updated successfully, but these errors were encountered: