Skip to content

Commit

Permalink
Fix #2281 - allow lists to accept list types
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Nov 1, 2019
1 parent 050eb82 commit bab7e46
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Psalm/Type/Atomic/TList.php
Expand Up @@ -144,6 +144,12 @@ public function replaceTemplateTypesWithStandins(
} 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(
Expand Down
27 changes: 27 additions & 0 deletions tests/Template/ClassTemplateTest.php
Expand Up @@ -1864,6 +1864,33 @@ public function __construct()
/** @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"];
}'
],
];
}

Expand Down

0 comments on commit bab7e46

Please sign in to comment.