diff --git a/src/Visitor/UnusedMatchVisitor.php b/src/Visitor/UnusedMatchVisitor.php index f30168d..d1c137d 100644 --- a/src/Visitor/UnusedMatchVisitor.php +++ b/src/Visitor/UnusedMatchVisitor.php @@ -5,6 +5,7 @@ use PhpParser\Node; use PhpParser\Node\Arg; use PhpParser\Node\ArrayItem; +use PhpParser\Node\Expr\ArrowFunction; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\AssignOp; use PhpParser\Node\Expr\BinaryOp\Coalesce; @@ -86,7 +87,8 @@ private function isUsed(Node $parent): bool || $parent instanceof Ternary || $parent instanceof MatchArm || $parent instanceof Yield_ - || $parent instanceof YieldFrom; + || $parent instanceof YieldFrom + || $parent instanceof ArrowFunction; } } diff --git a/tests/Rule/data/ForbidUnusedMatchResultRule/code.php b/tests/Rule/data/ForbidUnusedMatchResultRule/code.php index f96c8ce..df26b30 100644 --- a/tests/Rule/data/ForbidUnusedMatchResultRule/code.php +++ b/tests/Rule/data/ForbidUnusedMatchResultRule/code.php @@ -70,6 +70,18 @@ public function testUsed(bool $bool): mixed 1 => 'y', } : null; + function ($int) { + return match ($int) { + 0 => 'x', + 1 => 'y', + }; + }; + + fn () => match ($int) { + 0 => 'x', + 1 => 'y', + }; + return match ($bool) { false => 1, true => 2,