1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Fix #4209 - allow hinting arrow function return type

This commit is contained in:
Brown 2020-09-19 14:59:19 -04:00
parent a8a2a4cb66
commit f973937aec
2 changed files with 17 additions and 0 deletions

View File

@ -144,6 +144,14 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer
$function_stmts = $this->function->getStmts() ?: [];
if ($this->function instanceof ArrowFunction
&& isset($function_stmts[0])
&& $function_stmts[0] instanceof PhpParser\Node\Stmt\Return_
&& $function_stmts[0]->expr
) {
$function_stmts[0]->setAttributes($function_stmts[0]->expr->getAttributes());
}
$hash = null;
$real_method_id = null;
$method_id = null;

View File

@ -510,6 +510,15 @@ class ClosureTest extends TestCase
'error_levels' => [],
'7.4'
],
'annotateShortClosureReturn' => [
'<?php
/** @psalm-suppress MissingReturnType */
function returnsBool() { return true; }
$a = fn() : bool => /** @var bool */ returnsBool();',
[],
[],
'7.4'
],
];
}