Skip to content
Permalink
Browse files

Fix #2526 - always check for array assignment in assignop

  • Loading branch information
muglug committed Dec 29, 2019
1 parent e3e3296 commit 0c7851ae21e09ebfa7992d58bfe1f9f6bfe43988
@@ -892,6 +892,7 @@ public static function analyzeAssignmentOperation(
$stmt_var_type = $stmt_var_type ? clone $stmt_var_type: null;

$stmt_expr_type = $statements_analyzer->node_data->getType($stmt->expr);
$result_type = null;

if ($stmt instanceof PhpParser\Node\Expr\AssignOp\Plus
|| $stmt instanceof PhpParser\Node\Expr\AssignOp\Minus
@@ -969,6 +970,16 @@ public static function analyzeAssignmentOperation(
}
}

if ($stmt->var instanceof PhpParser\Node\Expr\ArrayDimFetch) {
ArrayAssignmentAnalyzer::analyze(
$statements_analyzer,
$stmt->var,
$context,
null,
$result_type ?: Type::getEmpty()
);
}

if ($stmt instanceof PhpParser\Node\Expr\AssignOp\Coalesce) {
$old_data_provider = $statements_analyzer->node_data;

@@ -992,6 +992,16 @@ function test($var): void {}
test(true);
test(false);',
],
'assignOpUpdateArray' => [
'<?php
$optgroup = ["a" => ""];
if (rand(0, 1)) {
$optgroup["a"] .= "v";
}
if ($optgroup["a"] !== "") {}'
],
];
}

0 comments on commit 0c7851a

Please sign in to comment.
You can’t perform that action at this time.