diff --git a/src/PhpDoc/PhpDocNodeResolver.php b/src/PhpDoc/PhpDocNodeResolver.php index aa88501817..8b3745e590 100644 --- a/src/PhpDoc/PhpDocNodeResolver.php +++ b/src/PhpDoc/PhpDocNodeResolver.php @@ -160,9 +160,11 @@ public function resolvePropertyTags(PhpDocNode $phpDocNode, NameScope $nameScope public function resolveMethodTags(PhpDocNode $phpDocNode, NameScope $nameScope): array { $resolved = []; + $originalNameScope = $nameScope; foreach (['@method', '@psalm-method', '@phpstan-method'] as $tagName) { foreach ($phpDocNode->getMethodTagValues($tagName) as $tagValue) { + $nameScope = $originalNameScope; $templateTags = []; if (count($tagValue->templateTypes) > 0 && $nameScope->getClassName() !== null) { diff --git a/tests/PHPStan/Analyser/data/generic-method-tags.php b/tests/PHPStan/Analyser/data/generic-method-tags.php index da7f89bd24..92fdfaef5c 100644 --- a/tests/PHPStan/Analyser/data/generic-method-tags.php +++ b/tests/PHPStan/Analyser/data/generic-method-tags.php @@ -6,6 +6,7 @@ /** * @method TVal doThing(TVal $param) + * @method TVal doAnotherThing(int $param) */ class Test { @@ -20,4 +21,5 @@ function test(int $int, string $string): void assertType('int', $test->doThing($int)); assertType('string', $test->doThing($string)); + assertType(TVal::class, $test->doAnotherThing($int)); }