Skip to content

Commit 624f71f

Browse files
hoelsnikic
authored andcommitted
Resolve return type of arrow functions (nikic#613)
1 parent 1bd73cc commit 624f71f

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

lib/PhpParser/NodeVisitor/NameResolver.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public function enterNode(Node $node) {
9191
$this->resolveSignature($node);
9292
} elseif ($node instanceof Stmt\ClassMethod
9393
|| $node instanceof Expr\Closure
94+
|| $node instanceof Expr\ArrowFunction
9495
) {
9596
$this->resolveSignature($node);
9697
} elseif ($node instanceof Stmt\Property) {

test/PhpParser/NodeVisitor/NameResolverTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,10 @@ function(A $a) : A {};
219219
function fn3(?A $a) : ?A {}
220220
function fn4(?array $a) : ?array {}
221221
222+
fn(array $a): array => $a;
223+
fn(A $a): A => $a;
224+
fn(?A $a): ?A => $a;
225+
222226
A::b();
223227
A::$b;
224228
A::B;
@@ -263,6 +267,9 @@ function fn3(?\NS\A $a) : ?\NS\A
263267
function fn4(?array $a) : ?array
264268
{
265269
}
270+
fn(array $a): array => $a;
271+
fn(\NS\A $a): \NS\A => $a;
272+
fn(?\NS\A $a): ?\NS\A => $a;
266273
\NS\A::b();
267274
\NS\A::$b;
268275
\NS\A::B;

0 commit comments

Comments
 (0)