mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
Fix #3928 - preserve list-ness when assigning with no offset
This commit is contained in:
parent
6ed7a81146
commit
9dfdcbef31
@ -1057,10 +1057,16 @@ class ArrayFetchAnalyzer
|
||||
$type->count = $property_count;
|
||||
} else {
|
||||
$array_type->removeType($type_string);
|
||||
|
||||
if (!$stmt->dim && $type->is_list) {
|
||||
$type = new TList($generic_params);
|
||||
} else {
|
||||
$type = new TArray([
|
||||
$new_key_type,
|
||||
$generic_params,
|
||||
]);
|
||||
}
|
||||
|
||||
$array_type->addType($type);
|
||||
}
|
||||
|
||||
|
@ -437,6 +437,21 @@ class WhileTest extends \Psalm\Tests\TestCase
|
||||
}
|
||||
}'
|
||||
],
|
||||
'assignToObjectLikeListPreserveListness' => [
|
||||
'<?php
|
||||
/**
|
||||
* @return non-empty-list<string>
|
||||
*/
|
||||
function foo(string $key): array {
|
||||
$elements = [$key];
|
||||
|
||||
while (rand(0, 1)) {
|
||||
$elements[] = $key;
|
||||
}
|
||||
|
||||
return $elements;
|
||||
}',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user