Skip to content

Commit 69059a5

Browse files
authored
forbidUnusedMatchResult: fix false positive for usage in arrow function (#305)
1 parent 879bcdc commit 69059a5

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/Visitor/UnusedMatchVisitor.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use PhpParser\Node;
66
use PhpParser\Node\Arg;
77
use PhpParser\Node\ArrayItem;
8+
use PhpParser\Node\Expr\ArrowFunction;
89
use PhpParser\Node\Expr\Assign;
910
use PhpParser\Node\Expr\AssignOp;
1011
use PhpParser\Node\Expr\BinaryOp\Coalesce;
@@ -86,7 +87,8 @@ private function isUsed(Node $parent): bool
8687
|| $parent instanceof Ternary
8788
|| $parent instanceof MatchArm
8889
|| $parent instanceof Yield_
89-
|| $parent instanceof YieldFrom;
90+
|| $parent instanceof YieldFrom
91+
|| $parent instanceof ArrowFunction;
9092
}
9193

9294
}

tests/Rule/data/ForbidUnusedMatchResultRule/code.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,18 @@ public function testUsed(bool $bool): mixed
7070
1 => 'y',
7171
} : null;
7272

73+
function ($int) {
74+
return match ($int) {
75+
0 => 'x',
76+
1 => 'y',
77+
};
78+
};
79+
80+
fn () => match ($int) {
81+
0 => 'x',
82+
1 => 'y',
83+
};
84+
7385
return match ($bool) {
7486
false => 1,
7587
true => 2,

0 commit comments

Comments
 (0)