diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/CoalesceAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/CoalesceAnalyzer.php index 78c913554..11fe52a21 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/CoalesceAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/CoalesceAnalyzer.php @@ -32,6 +32,8 @@ class CoalesceAnalyzer || $root_expr instanceof PhpParser\Node\Expr\MethodCall || $root_expr instanceof PhpParser\Node\Expr\StaticCall || $root_expr instanceof PhpParser\Node\Expr\Cast + || $root_expr instanceof PhpParser\Node\Expr\NullsafePropertyFetch + || $root_expr instanceof PhpParser\Node\Expr\NullsafeMethodCall ) { $left_var_id = '$' . (int) $left_expr->getAttribute('startFilePos'); diff --git a/tests/PropertyTypeTest.php b/tests/PropertyTypeTest.php index c443ef473..ae1cb7ebd 100644 --- a/tests/PropertyTypeTest.php +++ b/tests/PropertyTypeTest.php @@ -2395,6 +2395,19 @@ class PropertyTypeTest extends TestCase echo $foo->{$b} ?? null; }' ], + 'nullCoalesceWithNullablePropertyAccess' => [ + 'a ?? "default"; + }', + [], + [], + '8.0' + ], ]; }