Skip to content

Commit

Permalink
Don’t merge array and Traversable to iterable when there are intersec…
Browse files Browse the repository at this point in the history
…tions
  • Loading branch information
muglug committed Oct 12, 2020
1 parent f5ed655 commit 3887506
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Psalm/Internal/Type/TypeCombination.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ public static function combineTypes(
|| (isset($combination->named_object_types['Traversable'])
&& $combination->named_object_types['Traversable']->from_docblock)
)
&& !$combination->extra_types
) {
$array_param_types = $combination->array_type_params;
$traversable_param_types = $combination->builtin_type_params['Traversable']
Expand Down
12 changes: 12 additions & 0 deletions tests/ArrayAccessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,18 @@ function foo(array $arr) : void {
}
}'
],
'arrayAccessOnArraylikeObjectOrArray' => [
'<?php
/**
* @param (Traversable<int, string>&ArrayAccess<int, string>)|array<int, string> $arr
*/
function test($arr): string {
return $arr[0] ?? "";
}
test(["a", "b"]);
test(new ArrayObject(["a", "b"]));'
],
];
}

Expand Down

0 comments on commit 3887506

Please sign in to comment.