Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 777e91a

Browse files
bug #61004 [TypeInfo] Fix imported-only alias resolving (mtarld)
This PR was merged into the 7.3 branch. Discussion ---------- [TypeInfo] Fix imported-only alias resolving | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #60997 | License | MIT Fix type alias resolving when aliases are only coming from imports. Commits ------- d19800f [TypeInfo] Fix imported-only alias resolving
2 parents 3ba5d5e + d19800f commit 777e91a

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/Symfony/Component/TypeInfo/Tests/Fixtures/DummyWithTypeAliases.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ final class DummyWithTypeAliases
5757
public mixed $psalmOtherAliasedExternalAlias;
5858
}
5959

60+
/**
61+
* @phpstan-import-type CustomInt from DummyWithPhpDoc
62+
*/
63+
final class DummyWithImportedOnlyTypeAliases
64+
{
65+
/**
66+
* @var CustomInt
67+
*/
68+
public mixed $externalAlias;
69+
}
70+
6071
/**
6172
* @phpstan-type Foo = array{0: Bar}
6273
* @phpstan-type Bar = array{0: Foo}

src/Symfony/Component/TypeInfo/Tests/TypeContext/TypeContextFactoryTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\TypeInfo\Exception\LogicException;
1616
use Symfony\Component\TypeInfo\Tests\Fixtures\AbstractDummy;
1717
use Symfony\Component\TypeInfo\Tests\Fixtures\Dummy;
18+
use Symfony\Component\TypeInfo\Tests\Fixtures\DummyWithImportedOnlyTypeAliases;
1819
use Symfony\Component\TypeInfo\Tests\Fixtures\DummyWithInvalidTypeAlias;
1920
use Symfony\Component\TypeInfo\Tests\Fixtures\DummyWithInvalidTypeAliasImport;
2021
use Symfony\Component\TypeInfo\Tests\Fixtures\DummyWithRecursiveTypeAliases;
@@ -179,6 +180,10 @@ public function testCollectTypeAliases()
179180
'PsalmCustomArray' => Type::arrayShape([0 => Type::int(), 1 => Type::string(), 2 => Type::bool()]),
180181
'PsalmAliasedCustomInt' => Type::int(),
181182
], $this->typeContextFactory->createFromReflection(new \ReflectionProperty(DummyWithTypeAliases::class, 'localAlias'))->typeAliases);
183+
184+
$this->assertEquals([
185+
'CustomInt' => Type::int(),
186+
], $this->typeContextFactory->createFromReflection(new \ReflectionClass(DummyWithImportedOnlyTypeAliases::class))->typeAliases);
182187
}
183188

184189
public function testDoNotCollectTypeAliasesWhenToStringTypeResolver()

src/Symfony/Component/TypeInfo/TypeContext/TypeContextFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ private function collectTypeAliases(\ReflectionClass $reflection, TypeContext $t
241241
private function resolveTypeAliases(array $toResolve, array $resolved, TypeContext $typeContext): array
242242
{
243243
if (!$toResolve) {
244-
return [];
244+
return $resolved;
245245
}
246246

247247
$typeContext = new TypeContext(

0 commit comments

Comments
 (0)