From 70075e778ced55d76fa72fefd1203f58e1653d9a Mon Sep 17 00:00:00 2001 From: robchett Date: Thu, 9 Nov 2023 16:44:53 +0000 Subject: [PATCH] Allow type aliases for static variables Fixes #3837 --- src/Psalm/Internal/Analyzer/CommentAnalyzer.php | 5 +++++ tests/AnnotationTest.php | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/Psalm/Internal/Analyzer/CommentAnalyzer.php b/src/Psalm/Internal/Analyzer/CommentAnalyzer.php index 7428f91f3..ea50398ba 100644 --- a/src/Psalm/Internal/Analyzer/CommentAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/CommentAnalyzer.php @@ -432,6 +432,10 @@ final class CommentAnalyzer $var_comments = []; try { + $file_path = $statements_analyzer->getRootFilePath(); + $file_storage_provider = $codebase->file_storage_provider; + $file_storage = $file_storage_provider->get($file_path); + $var_comments = $codebase->config->disable_var_parsing ? [] : self::arrayToDocblocks( @@ -440,6 +444,7 @@ final class CommentAnalyzer $statements_analyzer->getSource(), $statements_analyzer->getSource()->getAliases(), $statements_analyzer->getSource()->getTemplateTypeMap(), + $file_storage->type_aliases, ); } catch (IncorrectDocblockException $e) { IssueBuffer::maybeAdd( diff --git a/tests/AnnotationTest.php b/tests/AnnotationTest.php index defd951aa..cdd002de2 100644 --- a/tests/AnnotationTest.php +++ b/tests/AnnotationTest.php @@ -1013,6 +1013,21 @@ class AnnotationTest extends TestCase return json_decode($json, true); }', ], + 'psalmTypeAnnotationForStaticVar' => [ + 'code' => ' [ 'code' => '