Skip to content

Commit

Permalink
Fix #2642 - merging two explicit lists is still a list
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Jan 17, 2020
1 parent adf230e commit 24e1d54
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
Expand Up @@ -78,6 +78,10 @@ public static function getFunctionReturnType(
);
}

if (!$unpacked_type_part->is_list) {
$all_nonempty_lists = false;
}

$unpacked_type_part = $unpacked_type_part->getGenericArrayType();
} elseif ($unpacked_type_part instanceof Type\Atomic\TList) {
$generic_properties = null;
Expand All @@ -99,6 +103,7 @@ public static function getFunctionReturnType(
}
} elseif (!$unpacked_type_part->type_params[0]->isEmpty()) {
$generic_properties = null;
$all_nonempty_lists = false;
}

if ($unpacked_type_part instanceof Type\Atomic\TArray) {
Expand Down Expand Up @@ -128,9 +133,13 @@ public static function getFunctionReturnType(
}

if ($generic_properties) {
return new Type\Union([
new Type\Atomic\ObjectLike($generic_properties),
]);
$objectlike = new Type\Atomic\ObjectLike($generic_properties);

if ($all_nonempty_lists) {
$objectlike->is_list = true;
}

return new Type\Union([$objectlike]);
}

if ($inner_value_types) {
Expand Down
11 changes: 11 additions & 0 deletions tests/FunctionCallTest.php
Expand Up @@ -2475,6 +2475,17 @@ function($x) {
'$b' => 'array<int, B>',
],
],
'arrayMergeTwoExplicitLists' => [
'<?php
/**
* @param list<int> $foo
*/
function foo(array $foo) : void {}
$foo1 = [1, 2, 3];
$foo2 = [1, 4, 5];
foo(array_merge($foo1, $foo2));'
],
];
}

Expand Down

0 comments on commit 24e1d54

Please sign in to comment.