Skip to content

Commit

Permalink
The issue message #9807
Browse files Browse the repository at this point in the history
This change makes the error messages more understandable. Instead of:
Type array<array-key, mixed> for $<tmp coalesce var>101 is never null
You'll now see something like:
Type array<array-key, mixed> for $coalesce_temp_line7_pos101 is never null
  • Loading branch information
wetas2020 committed Jan 18, 2025
1 parent 5abbdf3 commit b37a61c
Showing 1 changed file with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = '$<tmp coalesce var>' . (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;
Expand Down Expand Up @@ -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;
}
}
}

0 comments on commit b37a61c

Please sign in to comment.