1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-29 20:28:59 +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 committed by Daniil Gentili
parent 5a0e9d0965
commit 051169f9f2
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
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'
],
];
}