mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Memoize coalesce expression in more scenarios
This commit is contained in:
parent
7cc0f65f11
commit
fd7afc9c40
@ -20,10 +20,18 @@ class CoalesceAnalyzer
|
||||
) : bool {
|
||||
$left_expr = $stmt->left;
|
||||
|
||||
if ($left_expr instanceof PhpParser\Node\Expr\FuncCall
|
||||
|| $left_expr instanceof PhpParser\Node\Expr\MethodCall
|
||||
|| $left_expr instanceof PhpParser\Node\Expr\StaticCall
|
||||
|| $left_expr instanceof PhpParser\Node\Expr\Cast
|
||||
$root_expr = $left_expr;
|
||||
|
||||
while ($root_expr instanceof PhpParser\Node\Expr\ArrayDimFetch
|
||||
|| $root_expr instanceof PhpParser\Node\Expr\PropertyFetch
|
||||
) {
|
||||
$root_expr = $root_expr->var;
|
||||
}
|
||||
|
||||
if ($root_expr instanceof PhpParser\Node\Expr\FuncCall
|
||||
|| $root_expr instanceof PhpParser\Node\Expr\MethodCall
|
||||
|| $root_expr instanceof PhpParser\Node\Expr\StaticCall
|
||||
|| $root_expr instanceof PhpParser\Node\Expr\Cast
|
||||
) {
|
||||
$left_var_id = '$<tmp coalesce var>' . (int) $left_expr->getAttribute('startFilePos');
|
||||
|
||||
@ -31,6 +39,10 @@ class CoalesceAnalyzer
|
||||
|
||||
$condition_type = $statements_analyzer->node_data->getType($left_expr) ?: Type::getMixed();
|
||||
|
||||
if ($root_expr !== $left_expr) {
|
||||
$condition_type->possibly_undefined = true;
|
||||
}
|
||||
|
||||
$context->vars_in_scope[$left_var_id] = $condition_type;
|
||||
|
||||
$left_expr = new PhpParser\Node\Expr\Variable(
|
||||
|
Loading…
Reference in New Issue
Block a user