1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

Fix #1240 - reconcile array to iterable in template replacement

This commit is contained in:
Brown 2019-01-25 10:17:41 -05:00
parent c0f3197790
commit bed1f15e09
2 changed files with 21 additions and 0 deletions

View File

@ -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;

View File

@ -2033,6 +2033,22 @@ class TemplateTest extends TestCase
*/
class SomeRepository extends Repository {}'
],
'upcastArrayToIterable' => [
'<?php
/**
* @template K
* @template V
* @param iterable<K,V> $collection
* @return V
* @psalm-suppress InvalidReturnType
*/
function first($collection) {}
$one = first([1,2,3]);',
[
'$one' => 'int',
]
],
];
}