8000 [TypeInfo] Fix imported-only alias resolving by mtarld · Pull Request #61004 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[TypeInfo] Fix imported-only alias resolving #61004

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[TypeInfo] Fix imported-only alias resolving
  • Loading branch information
mtarld committed Jul 1, 2025
commit d19800fe23c4b645e188b7d9b0663ce47e1dc1cb
< 10000 td class="blob-num blob-num-addition empty-cell">
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
0