mirror of
https://github.com/danog/psalm.git
synced 2024-12-02 09:37:59 +01:00
Memoize coalesce expression in more scenarios
This commit is contained in:
parent
7cc0f65f11
commit
fd7afc9c40
@ -20,10 +20,18 @@ class CoalesceAnalyzer
|
|||||||
) : bool {
|
) : bool {
|
||||||
$left_expr = $stmt->left;
|
$left_expr = $stmt->left;
|
||||||
|
|
||||||
if ($left_expr instanceof PhpParser\Node\Expr\FuncCall
|
$root_expr = $left_expr;
|
||||||
|| $left_expr instanceof PhpParser\Node\Expr\MethodCall
|
|
||||||
|| $left_expr instanceof PhpParser\Node\Expr\StaticCall
|
while ($root_expr instanceof PhpParser\Node\Expr\ArrayDimFetch
|
||||||
|| $left_expr instanceof PhpParser\Node\Expr\Cast
|
|| $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');
|
$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();
|
$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;
|
$context->vars_in_scope[$left_var_id] = $condition_type;
|
||||||
|
|
||||||
$left_expr = new PhpParser\Node\Expr\Variable(
|
$left_expr = new PhpParser\Node\Expr\Variable(
|
||||||
|
Loading…
Reference in New Issue
Block a user