Skip to content

Commit

Permalink
Resolve typedefs that are used in var docblocks of foreach (#4037)
Browse files Browse the repository at this point in the history
Fixes #4029
  • Loading branch information
weirdan authored Aug 22, 2020
1 parent e62e964 commit 5bf7cc6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,17 @@ 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 {
$var_comments = CommentAnalyzer::getTypeFromComment(
$doc_comment,
$statements_analyzer->getSource(),
$statements_analyzer->getSource()->getAliases(),
$statements_analyzer->getTemplateTypeMap() ?: []
$statements_analyzer->getTemplateTypeMap() ?: [],
$type_aliases
);
} catch (DocblockParseException $e) {
if (IssueBuffer::accepts(
Expand Down
11 changes: 11 additions & 0 deletions tests/TypeAnnotationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,17 @@ private function b(int $type): void
}
}'
],
'usedInVarForForeach' => [
'<?php
/** @psalm-type _B=array{p1:string} */
function e(array $a): void
{
/** @var _B $elt */
foreach ($a as $elt) {
echo $elt["p1"];
}
}'
]
];
}

Expand Down

0 comments on commit 5bf7cc6

Please sign in to comment.