1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Fix array key check after direct assignment

This commit is contained in:
Matt Brown 2018-04-09 18:02:45 -04:00
parent d3fa972fab
commit 47255fb19b
2 changed files with 16 additions and 0 deletions

View File

@ -240,6 +240,7 @@ class ArrayAssignmentChecker
}
$new_child_type->removeType('null');
$new_child_type->possibly_undefined = false;
if (!$child_stmt->inferredType->hasObjectType()) {
$child_stmt->inferredType = $new_child_type;

View File

@ -983,6 +983,21 @@ class LoopScopeTest extends TestCase
$value = 6;
} while ($count);',
],
'arrayKeyJustSetInLoop' => [
'<?php
$a = null;
$arr = [];
foreach ([1, 2, 3] as $_) {
if (rand(0, 1)) {
$arr["a"]["c"] = "foo";
$a = $arr["a"]["c"];
} else {
$arr["b"]["c"] = "bar";
$a = $arr["b"]["c"];
}
}',
],
];
}