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:
parent
a8a2a4cb66
commit
f973937aec
@ -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;
|
||||
|
@ -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'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user