Skip to content
Permalink
Browse files

Fix #2457 - allow psalm-type aliases to be used above return type

  • Loading branch information
muglug committed Dec 11, 2019
1 parent 4b715cd commit 3a7dd61889b72cb7ac386ad9b2224a4dcd20c8c1
Showing with 21 additions and 1 deletion.
  1. +6 −1 src/Psalm/Internal/Analyzer/Statements/ReturnAnalyzer.php
  2. +15 −0 tests/AnnotationTest.php
@@ -55,13 +55,18 @@ public static function analyze(
$codebase = $statements_analyzer->getCodebase();

if ($doc_comment && ($parsed_docblock = $statements_analyzer->getParsedDocblock())) {
$file_storage_provider = $codebase->file_storage_provider;

$file_storage = $file_storage_provider->get($statements_analyzer->getFilePath());

try {
$var_comments = CommentAnalyzer::arrayToDocblocks(
$doc_comment,
$parsed_docblock,
$statements_analyzer->getSource(),
$statements_analyzer->getAliases(),
$statements_analyzer->getTemplateTypeMap()
$statements_analyzer->getTemplateTypeMap(),
$file_storage->type_aliases
);
} catch (DocblockParseException $e) {
if (IssueBuffer::accepts(
@@ -1031,6 +1031,21 @@ interface I {
public static function barBar();
}',
],
'psalmTypeAnnotationAboveReturn' => [
'<?php
/**
* @psalm-type Person = array{name: string, age: int}
*/
/**
* @psalm-return Person
*/
function getPerson_error(): array {
$json = \'{"name": "John", "age": 44}\';
/** @psalm-var Person */
return json_decode($json, true);
}'
],
];
}

0 comments on commit 3a7dd61

Please sign in to comment.
You can’t perform that action at this time.