1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-02 17:52:45 +01:00

Generate properly shaped lists when appending

This commit is contained in:
Daniil Gentili 2022-11-27 20:52:42 +01:00
parent 909edb48e3
commit 2b9512ef50
2 changed files with 20 additions and 0 deletions

View File

@ -590,6 +590,11 @@ class ArrayAssignmentAnalyzer
$array_atomic_type_class_string->getStandinKeyParam(),
$array_atomic_type_class_string->value_param
]);
} elseif ($atomic_root_types['array'] instanceof TKeyedArray
&& $atomic_root_types['array']->is_list
&& $atomic_root_types['array']->fallback_params === null
) {
$array_atomic_type = $atomic_root_types['array'];
} elseif ($atomic_root_types['array'] instanceof TNonEmptyArray
|| ($atomic_root_types['array'] instanceof TKeyedArray
&& $atomic_root_types['array']->is_list

View File

@ -2011,6 +2011,21 @@ class ArrayAssignmentTest extends TestCase
if (\array_key_exists($currentAction, $items)) {
$items[$currentAction]["active"] = true;
}'
],
'listAppendShape' => [
'code' => '<?php
$a = [];
$a[]= 0;
$a[]= 1;
$a[]= 2;
$b = [0];
$b[]= 1;
$b[]= 2;',
'assertions' => [
'$a===' => 'list{0, 1, 2}',
'$b===' => 'list{0, 1, 2}'
]
]
];
}