1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Fix #2476 - flesh out iterable params

This commit is contained in:
Matthew Brown 2019-12-18 17:19:54 +00:00
parent 9d8ca08fb9
commit 734ad02203
2 changed files with 26 additions and 1 deletions

View File

@ -1330,7 +1330,10 @@ class ExpressionAnalyzer
return $return_type;
}
if ($return_type instanceof Type\Atomic\TArray || $return_type instanceof Type\Atomic\TGenericObject) {
if ($return_type instanceof Type\Atomic\TArray
|| $return_type instanceof Type\Atomic\TGenericObject
|| $return_type instanceof Type\Atomic\TIterable
) {
foreach ($return_type->type_params as &$type_param) {
$type_param = self::fleshOutType(
$codebase,

View File

@ -661,6 +661,28 @@ class ReturnTypeTest extends TestCase
}
}',
],
'allowIterableReturnTypeCrossover' => [
'<?php
class Foo {
public const TYPE1 = "a";
public const TYPE2 = "b";
public const AVAILABLE_TYPES = [
self::TYPE1,
self::TYPE2,
];
/**
* @return iterable<array-key, array{foo: value-of<self::AVAILABLE_TYPES>}>
*/
public function foo() {
return [
["foo" => self::TYPE1],
["foo" => self::TYPE2]
];
}
}',
],
];
}