mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Fix array_merge edge case
This commit is contained in:
parent
5132de22e0
commit
992f26a8e7
@ -130,10 +130,18 @@ class ArrayMergeReturnTypeProvider implements FunctionReturnTypeProviderInterfac
|
||||
$class_strings[$key] = true;
|
||||
}
|
||||
|
||||
if (!isset($generic_properties[$key]) || !$type->possibly_undefined) {
|
||||
if (!isset($generic_properties[$key]) || (
|
||||
!$type->possibly_undefined
|
||||
&& !$unpacking_possibly_empty
|
||||
&& $is_replace
|
||||
)) {
|
||||
if ($unpacking_possibly_empty) {
|
||||
$type = $type->setPossiblyUndefined(true);
|
||||
}
|
||||
$generic_properties[$key] = $type;
|
||||
} else {
|
||||
$was_possibly_undefined = $generic_properties[$key]->possibly_undefined;
|
||||
$was_possibly_undefined = $generic_properties[$key]->possibly_undefined
|
||||
|| $unpacking_possibly_empty;
|
||||
|
||||
$generic_properties[$key] = Type::combineUnionTypes(
|
||||
$generic_properties[$key],
|
||||
@ -147,7 +155,7 @@ class ArrayMergeReturnTypeProvider implements FunctionReturnTypeProviderInterfac
|
||||
}
|
||||
}
|
||||
|
||||
if (!$unpacked_type_part->is_list && !$unpacking_possibly_empty) {
|
||||
if (!$unpacked_type_part->is_list) {
|
||||
$all_nonempty_lists = false;
|
||||
}
|
||||
|
||||
|
@ -211,6 +211,24 @@ class ArrayFunctionCallTest extends TestCase
|
||||
'ignored_issues' => [],
|
||||
'php_version' => '8.0',
|
||||
],
|
||||
'arrayMergeListOfShapes' => [
|
||||
'code' => '<?php
|
||||
|
||||
/** @var list<array{a: int}> */
|
||||
$a = [];
|
||||
|
||||
$b = array_merge(...$a);
|
||||
|
||||
/** @var non-empty-list<array{a: int}> */
|
||||
$c = [];
|
||||
|
||||
$d = array_merge(...$c);
|
||||
',
|
||||
'assertions' => [
|
||||
'$b' => 'array{a?: int}',
|
||||
'$d' => 'array{a: int}',
|
||||
]
|
||||
],
|
||||
'arrayMergeIntArrays' => [
|
||||
'code' => '<?php
|
||||
$d = array_merge(["a", "b", "c", "d"], [1, 2, 3]);',
|
||||
|
Loading…
x
Reference in New Issue
Block a user