Skip to content

Commit

Permalink
Merge pull request #7002 from orklah/listkeyedarray
Browse files Browse the repository at this point in the history
Disable list flag for TKeyedArray after unset
  • Loading branch information
orklah committed Nov 26, 2021
2 parents 2fbad1b + 4f223db commit a27e729
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Psalm/Internal/Analyzer/Statements/UnsetAnalyzer.php
Expand Up @@ -50,6 +50,7 @@ public static function analyze(
|| $var->dim instanceof PhpParser\Node\Scalar\LNumber
) {
if (isset($atomic_root_type->properties[$var->dim->value])) {
$atomic_root_type->is_list = false;
unset($atomic_root_type->properties[$var->dim->value]);
$root_type->bustCache(); //remove id cache
}
Expand Down
7 changes: 7 additions & 0 deletions tests/ArrayAccessTest.php
Expand Up @@ -1024,6 +1024,13 @@ function f($p): int {
return $p["name"];
}'
],
'unsetListKeyedArrayDisableListFlag' => [
'<?php
$a = ["a", "b"];
unset($a[0]);
',
'assertions' => ['$a===' => 'array{1: "b"}']
],
];
}

Expand Down

0 comments on commit a27e729

Please sign in to comment.