Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable list flag for TKeyedArray after unset #7002

Merged
merged 1 commit into from Nov 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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]);
Comment on lines +1029 to +1030
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be improved by keeping the flag when last element is being unset.

',
'assertions' => ['$a===' => 'array{1: "b"}']
],
];
}

Expand Down