diff --git a/src/Psalm/Type/Union.php b/src/Psalm/Type/Union.php index b4bc48a00..6d39a3f71 100644 --- a/src/Psalm/Type/Union.php +++ b/src/Psalm/Type/Union.php @@ -913,6 +913,11 @@ class Union break; } + if ($input_key === 'array' && $key === 'iterable') { + $matching_atomic_type = $atomic_input_type; + break; + } + if (strpos($input_key, $key . '&') === 0) { $matching_atomic_type = $atomic_input_type; break; diff --git a/tests/TemplateTest.php b/tests/TemplateTest.php index 6e15cc5be..aded7ac5a 100644 --- a/tests/TemplateTest.php +++ b/tests/TemplateTest.php @@ -2033,6 +2033,22 @@ class TemplateTest extends TestCase */ class SomeRepository extends Repository {}' ], + 'upcastArrayToIterable' => [ + ' $collection + * @return V + * @psalm-suppress InvalidReturnType + */ + function first($collection) {} + + $one = first([1,2,3]);', + [ + '$one' => 'int', + ] + ], ]; }