diff --git a/src/Symfony/Component/TypeInfo/Tests/Fixtures/DummyWithTypeAliases.php b/src/Symfony/Component/TypeInfo/Tests/Fixtures/DummyWithTypeAliases.php index 7f73190df154..85f5784dd2cf 100644 --- a/src/Symfony/Component/TypeInfo/Tests/Fixtures/DummyWithTypeAliases.php +++ b/src/Symfony/Component/TypeInfo/Tests/Fixtures/DummyWithTypeAliases.php @@ -57,6 +57,17 @@ final class DummyWithTypeAliases public mixed $psalmOtherAliasedExternalAlias; } +/** + * @phpstan-import-type CustomInt from DummyWithPhpDoc + */ +final class DummyWithImportedOnlyTypeAliases +{ + /** + * @var CustomInt + */ + public mixed $externalAlias; +} + /** * @phpstan-type Foo = array{0: Bar} * @phpstan-type Bar = array{0: Foo} diff --git a/src/Symfony/Component/TypeInfo/Tests/TypeContext/TypeContextFactoryTest.php b/src/Symfony/Component/TypeInfo/Tests/TypeContext/TypeContextFactoryTest.php index cf0f1bb91179..532ba3984250 100644 --- a/src/Symfony/Component/TypeInfo/Tests/TypeContext/TypeContextFactoryTest.php +++ b/src/Symfony/Component/TypeInfo/Tests/TypeContext/TypeContextFactoryTest.php @@ -15,6 +15,7 @@ use Symfony\Component\TypeInfo\Exception\LogicException; use Symfony\Component\TypeInfo\Tests\Fixtures\AbstractDummy; use Symfony\Component\TypeInfo\Tests\Fixtures\Dummy; +use Symfony\Component\TypeInfo\Tests\Fixtures\DummyWithImportedOnlyTypeAliases; use Symfony\Component\TypeInfo\Tests\Fixtures\DummyWithInvalidTypeAlias; use Symfony\Component\TypeInfo\Tests\Fixtures\DummyWithInvalidTypeAliasImport; use Symfony\Component\TypeInfo\Tests\Fixtures\DummyWithRecursiveTypeAliases; @@ -179,6 +180,10 @@ public function testCollectTypeAliases() 'PsalmCustomArray' => Type::arrayShape([0 => Type::int(), 1 => Type::string(), 2 => Type::bool()]), 'PsalmAliasedCustomInt' => Type::int(), ], $this->typeContextFactory->createFromReflection(new \ReflectionProperty(DummyWithTypeAliases::class, 'localAlias'))->typeAliases); + + $this->assertEquals([ + 'CustomInt' => Type::int(), + ], $this->typeContextFactory->createFromReflection(new \ReflectionClass(DummyWithImportedOnlyTypeAliases::class))->typeAliases); } public function testDoNotCollectTypeAliasesWhenToStringTypeResolver() diff --git a/src/Symfony/Component/TypeInfo/TypeContext/TypeContextFactory.php b/src/Symfony/Component/TypeInfo/TypeContext/TypeContextFactory.php index 8e1cc3d4314e..a7564557e555 100644 --- a/src/Symfony/Component/TypeInfo/TypeContext/TypeContextFactory.php +++ b/src/Symfony/Component/TypeInfo/TypeContext/TypeContextFactory.php @@ -241,7 +241,7 @@ private function collectTypeAliases(\ReflectionClass $reflection, TypeContext $t private function resolveTypeAliases(array $toResolve, array $resolved, TypeContext $typeContext): array { if (!$toResolve) { - return []; + return $resolved; } $typeContext = new TypeContext(