1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

Fix #5097 - memoise more things during null coalesce

This commit is contained in:
Matt Brown 2021-01-26 23:10:57 -05:00
parent 76269658ca
commit 3c58220f3a
2 changed files with 15 additions and 0 deletions

View File

@ -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 = '$<tmp coalesce var>' . (int) $left_expr->getAttribute('startFilePos');

View File

@ -2395,6 +2395,19 @@ class PropertyTypeTest extends TestCase
echo $foo->{$b} ?? null;
}'
],
'nullCoalesceWithNullablePropertyAccess' => [
'<?php
class Bar {
public ?string $a = null;
}
function takesBar(?Bar $bar) : string {
return $bar?->a ?? "default";
}',
[],
[],
'8.0'
],
];
}