diff --git a/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeNodeScanner.php b/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeNodeScanner.php index ef659057e..494c888a0 100644 --- a/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeNodeScanner.php +++ b/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeNodeScanner.php @@ -592,11 +592,15 @@ class FunctionLikeNodeScanner $var_comment_readonly = false; $var_comment_allow_private_mutation = false; if ($doc_comment) { + $template_types = ($this->existing_function_template_types ?: []) + + ($classlike_storage->template_types ?: []) + ; + $var_comments = CommentAnalyzer::getTypeFromComment( $doc_comment, $this->file_scanner, $this->aliases, - $this->existing_function_template_types ?: [], + $template_types, $this->type_aliases, ); diff --git a/tests/Template/ClassTemplateTest.php b/tests/Template/ClassTemplateTest.php index 68a099ab2..4105b6dfb 100644 --- a/tests/Template/ClassTemplateTest.php +++ b/tests/Template/ClassTemplateTest.php @@ -4029,6 +4029,28 @@ class ClassTemplateTest extends TestCase $baz = new DoesNotExist(); foobar($baz);', ], + 'promoted property with template' => [ + 'code' => 't; + ', + 'assertions' => [ + '$a' => 'A', + '$t' => 'int', + ], + 'ignored_issues' => [], + 'php_version' => '8.0', + ], ]; }