From 3887506280c49b46f112441539b9ca5a1a44e98b Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Mon, 12 Oct 2020 18:55:57 -0400 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20merge=20array=20and=20Traversab?= =?UTF-8?q?le=20to=20iterable=20when=20there=20are=20intersections?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Psalm/Internal/Type/TypeCombination.php | 1 + tests/ArrayAccessTest.php | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/Psalm/Internal/Type/TypeCombination.php b/src/Psalm/Internal/Type/TypeCombination.php index 072c4afc283..82a698ab2b9 100644 --- a/src/Psalm/Internal/Type/TypeCombination.php +++ b/src/Psalm/Internal/Type/TypeCombination.php @@ -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'] diff --git a/tests/ArrayAccessTest.php b/tests/ArrayAccessTest.php index dcddb89e3de..13ef370d459 100644 --- a/tests/ArrayAccessTest.php +++ b/tests/ArrayAccessTest.php @@ -964,6 +964,18 @@ function foo(array $arr) : void { } }' ], + 'arrayAccessOnArraylikeObjectOrArray' => [ + '&ArrayAccess)|array $arr + */ + function test($arr): string { + return $arr[0] ?? ""; + } + + test(["a", "b"]); + test(new ArrayObject(["a", "b"]));' + ], ]; }