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:
parent
050eb82f04
commit
bab7e46983
@ -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(
|
||||
|
@ -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"];
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user