1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Fix #2281 - allow lists to accept list types

This commit is contained in:
Matthew Brown 2019-11-01 13:35:16 +00:00
parent 050eb82f04
commit bab7e46983
2 changed files with 33 additions and 0 deletions

View File

@ -144,6 +144,12 @@ class TList extends \Psalm\Type\Atomic
} else {
$input_type_param = $input_type->getGenericValueType();
}
} elseif ($input_type instanceof Atomic\TList) {
if ($offset === 0) {
continue;
}
$input_type_param = clone $input_type->type_param;
}
$type_param->replaceTemplateTypesWithStandins(

View File

@ -1864,6 +1864,33 @@ class ClassTemplateTest extends TestCase
/** @param Foo<array> $_ */
function takesFooArray($_): void {}',
],
'allowListAcceptance' => [
'<?php
/** @template T */
class Collection
{
/** @var list<T> */
public $values;
/** @param list<T> $values */
function __construct(array $values)
{
$this->values = $values;
}
}
/** @return Collection<string> */
function makeStringCollection()
{
return new Collection(getStringList()); // gets typed as Collection<mixed> for some reason
}
/** @return list<string> */
function getStringList(): array
{
return ["foo", "baz"];
}'
],
];
}