diff --git a/src/Reflection/ClassReflection.php b/src/Reflection/ClassReflection.php index a8c7913674..e2a9d32d27 100644 --- a/src/Reflection/ClassReflection.php +++ b/src/Reflection/ClassReflection.php @@ -1373,9 +1373,13 @@ public function getTypeAliases(): array $typeAliasImportTags = $resolvedPhpDoc->getTypeAliasImportTags(); $typeAliasTags = $resolvedPhpDoc->getTypeAliasTags(); + $localAliases = array_map(static fn (TypeAliasTag $typeAliasTag): TypeAlias => $typeAliasTag->getTypeAlias(), $typeAliasTags); // prevent circular imports if (array_key_exists($this->getName(), self::$resolvingTypeAliasImports)) { + if ($localAliases !== []) { + return $this->typeAliases = $localAliases; + } throw new CircularTypeAliasDefinitionException(); } @@ -1406,8 +1410,6 @@ public function getTypeAliases(): array unset(self::$resolvingTypeAliasImports[$this->getName()]); - $localAliases = array_map(static fn (TypeAliasTag $typeAliasTag): TypeAlias => $typeAliasTag->getTypeAlias(), $typeAliasTags); - $this->typeAliases = array_filter( array_merge($importedAliases, $localAliases), static fn (?TypeAlias $typeAlias): bool => $typeAlias !== null, diff --git a/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php b/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php index b7e36dbd96..2f5ce4e226 100644 --- a/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php +++ b/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php @@ -3900,4 +3900,21 @@ public function testBug6120(): void $this->analyse([__DIR__ . '/data/bug-6120.php'], []); } + public function testBug11463(): void + { + $this->checkThisOnly = false; + $this->checkNullables = true; + $this->checkUnionTypes = true; + $this->analyse([__DIR__ . '/../PhpDoc/data/bug-11463.php'], [ + [ + "Parameter #1 \$bar of method Bug11463\FooType::foo() expects 'bar', 'bla' given.", + 32, + ], + [ + "Parameter #1 \$foo of method Bug11463\BarType::bar() expects 'foo', 'bla' given.", + 35, + ], + ]); + } + } diff --git a/tests/PHPStan/Rules/PhpDoc/IncompatiblePhpDocTypeRuleTest.php b/tests/PHPStan/Rules/PhpDoc/IncompatiblePhpDocTypeRuleTest.php index 44d03ede8a..247dcce92b 100644 --- a/tests/PHPStan/Rules/PhpDoc/IncompatiblePhpDocTypeRuleTest.php +++ b/tests/PHPStan/Rules/PhpDoc/IncompatiblePhpDocTypeRuleTest.php @@ -487,4 +487,14 @@ public function testBug9708(): void $this->analyse([__DIR__ . '/data/bug-9708.php'], []); } + public function testBug11463(): void + { + $this->analyse([__DIR__ . '/data/bug-11463.php'], []); + } + + public function testBug11463b(): void + { + $this->analyse([__DIR__ . '/data/bug-11463b.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..2f5fc2e700 --- /dev/null +++ b/tests/PHPStan/Rules/PhpDoc/data/bug-11463.php @@ -0,0 +1,36 @@ +foo('bar'); + $foo->foo('bla'); + + $bar->bar('foo'); + $bar->bar('bla'); +} diff --git a/tests/PHPStan/Rules/PhpDoc/data/bug-11463b.php b/tests/PHPStan/Rules/PhpDoc/data/bug-11463b.php new file mode 100644 index 0000000000..e19b034689 --- /dev/null +++ b/tests/PHPStan/Rules/PhpDoc/data/bug-11463b.php @@ -0,0 +1,46 @@ +