Skip to content
Permalink
Browse files

Fix #2336 - detect used variable in mixed array offset

  • Loading branch information
muglug committed Nov 13, 2019
1 parent 4be3180 commit 7516b7b0cfe05c46274742ab16597b701c8c5d17
@@ -279,6 +279,21 @@ public static function updateArrayType(
if ($child_stmt->var->inferredType->hasMixed()) {
$full_var_id = false;
while ($child_stmts) {
$child_stmt = array_shift($child_stmts);
if ($child_stmt->dim) {
if (ExpressionAnalyzer::analyze(
$statements_analyzer,
$child_stmt->dim,
$context
) === false) {
return false;
}
}
}
break;
}
}
@@ -1251,6 +1251,26 @@ function foo() : void {
echo $a;'
],
'unusedForeach' => [
'<?php
/**
* @param array<int, string> $test
*/
function foo(array $test) : void {
foreach($test as $key => $_testValue) {
echo $key;
}
}'
],
'usedAfterMixedVariableAssignment' => [
'<?php
function foo(array $arr): array {
$c = "c";
/** @psalm-suppress MixedArrayAssignment */
$arr["a"]["b"][$c] = 1;
return $arr;
}',
]
];
}

0 comments on commit 7516b7b

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