diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/ForeachAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/ForeachAnalyzer.php index 5e4e1fcb666..662085d9929 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/ForeachAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/ForeachAnalyzer.php @@ -60,6 +60,8 @@ public static function analyze( $doc_comment = $stmt->getDocComment(); $codebase = $statements_analyzer->getCodebase(); + $file_path = $statements_analyzer->getRootFilePath(); + $type_aliases = $codebase->file_storage_provider->get($file_path)->type_aliases; if ($doc_comment) { try { @@ -67,7 +69,8 @@ public static function analyze( $doc_comment, $statements_analyzer->getSource(), $statements_analyzer->getSource()->getAliases(), - $statements_analyzer->getTemplateTypeMap() ?: [] + $statements_analyzer->getTemplateTypeMap() ?: [], + $type_aliases ); } catch (DocblockParseException $e) { if (IssueBuffer::accepts( diff --git a/tests/TypeAnnotationTest.php b/tests/TypeAnnotationTest.php index 86a1d041074..85d0fad4ff4 100644 --- a/tests/TypeAnnotationTest.php +++ b/tests/TypeAnnotationTest.php @@ -305,6 +305,17 @@ private function b(int $type): void } }' ], + 'usedInVarForForeach' => [ + '