1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Don’t merge array and Traversable to iterable when there are intersections

This commit is contained in:
Matt Brown 2020-10-12 12:45:31 -04:00 committed by Daniil Gentili
parent d6f8a658bf
commit 0934988ec7
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
2 changed files with 13 additions and 0 deletions

View File

@ -261,6 +261,7 @@ class TypeCombination
|| (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']

View File

@ -964,6 +964,18 @@ class ArrayAccessTest extends TestCase
}
}'
],
'arrayAccessOnArraylikeObjectOrArray' => [
'<?php
/**
* @param arraylike-object<int, string>|array<int, string> $arr
*/
function test($arr): string {
return $arr[0] ?? "";
}
test(["a", "b"]);
test(new ArrayObject(["a", "b"]));'
],
];
}