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

Expand template param before comparison

This commit is contained in:
Brown 2020-05-25 11:51:10 -04:00
parent be847472a2
commit 109920be88
2 changed files with 25 additions and 0 deletions

View File

@ -246,6 +246,15 @@ class TypeChecker extends NodeVisitor
if (isset(\array_values($expected_type_params)[$i])) {
$expected_type_param = \reset(\array_values($expected_type_params)[$i])[0];
$expected_type_param = \Psalm\Internal\Type\TypeExpander::expandUnion(
$codebase,
$expected_type_param,
$this->source->getFQCLN(),
$this->source->getFQCLN(),
$this->source->getParentFQCLN()
);
$template_name = \array_keys($expected_type_params)[$i];
$type_param = \Psalm\Internal\Type\TypeExpander::expandUnion(

View File

@ -2741,6 +2741,22 @@ class ClassTemplateTest extends TestCase
if (is_int($ret)) {}
}'
],
'templateWithLateResolvedType' => [
'<?php
/**
* @template A of Enum::TYPE_*
*/
class Foo {}
class Enum
{
const TYPE_ONE = 1;
const TYPE_TWO = 2;
}
/** @var Foo<Enum::TYPE_ONE> $foo */
$foo = new Foo();'
],
];
}