From b37a61caca62662c4d9821c54936a10f010c22dc Mon Sep 17 00:00:00 2001 From: EL GABOURI Saad Date: Sat, 18 Jan 2025 23:38:38 +0100 Subject: [PATCH] The issue message #9807 This change makes the error messages more understandable. Instead of: Type array for $101 is never null You'll now see something like: Type array for $coalesce_temp_line7_pos101 is never null --- .../Expression/BinaryOp/CoalesceAnalyzer.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/CoalesceAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/CoalesceAnalyzer.php index 72194f55224..d486881a385 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/CoalesceAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/CoalesceAnalyzer.php @@ -26,7 +26,6 @@ public static function analyze( Context $context ): bool { $left_expr = $stmt->left; - $root_expr = $left_expr; while ($root_expr instanceof PhpParser\Node\Expr\ArrayDimFetch @@ -44,7 +43,9 @@ public static function analyze( || $root_expr instanceof PhpParser\Node\Expr\NullsafeMethodCall || $root_expr instanceof PhpParser\Node\Expr\Ternary ) { - $left_var_id = '$' . (int) $left_expr->getAttribute('startFilePos'); + $start_pos = (int) $left_expr->getAttribute('startFilePos'); + $line_number = (int) $left_expr->getAttribute('startLine'); + $left_var_id = '$coalesce_temp_line' . $line_number . '_pos' . $start_pos; $cloned = clone $context; $cloned->inside_isset = true; @@ -81,17 +82,14 @@ public static function analyze( ); $old_node_data = $statements_analyzer->node_data; - $statements_analyzer->node_data = clone $statements_analyzer->node_data; ExpressionAnalyzer::analyze($statements_analyzer, $ternary, $context); $ternary_type = $statements_analyzer->node_data->getType($ternary) ?? Type::getMixed(); - $statements_analyzer->node_data = $old_node_data; - $statements_analyzer->node_data->setType($stmt, $ternary_type); return true; } -} +} \ No newline at end of file