diff --git a/src/Reflection/ClassReflection.php b/src/Reflection/ClassReflection.php index a8c7913674..b67064b5ec 100644 --- a/src/Reflection/ClassReflection.php +++ b/src/Reflection/ClassReflection.php @@ -1376,6 +1376,13 @@ public function getTypeAliases(): array // prevent circular imports if (array_key_exists($this->getName(), self::$resolvingTypeAliasImports)) { + // Return only local type aliases to break the cycle. + // Imported aliases are not available yet, but local ones + // don't depend on other classes and can be returned safely. + $localAliases = array_map(static fn (TypeAliasTag $typeAliasTag): TypeAlias => $typeAliasTag->getTypeAlias(), $typeAliasTags); + if ($localAliases !== []) { + return $localAliases; + } throw new CircularTypeAliasDefinitionException(); } diff --git a/tests/PHPStan/Rules/PhpDoc/IncompatiblePhpDocTypeRuleTest.php b/tests/PHPStan/Rules/PhpDoc/IncompatiblePhpDocTypeRuleTest.php index 44d03ede8a..5c2b248296 100644 --- a/tests/PHPStan/Rules/PhpDoc/IncompatiblePhpDocTypeRuleTest.php +++ b/tests/PHPStan/Rules/PhpDoc/IncompatiblePhpDocTypeRuleTest.php @@ -487,4 +487,9 @@ public function testBug9708(): void $this->analyse([__DIR__ . '/data/bug-9708.php'], []); } + public function testBug11463(): void + { + $this->analyse([__DIR__ . '/data/bug-11463.php'], []); + } + } diff --git a/tests/PHPStan/Rules/PhpDoc/data/bug-11463.php b/tests/PHPStan/Rules/PhpDoc/data/bug-11463.php new file mode 100644 index 0000000000..09235324b2 --- /dev/null +++ b/tests/PHPStan/Rules/PhpDoc/data/bug-11463.php @@ -0,0 +1,28 @@ +