-
-
Notifications
You must be signed in to change notification settings - Fork 946
Closed
Description
Bug report
It doesn't matter where in a match expression that the default is placed – it's only ever evaluated once all others have been (like in switch).
Code snippet that reproduces the problem
<?php
/**
* @param 1|2|3 $i
*/
function foo(int $i): int
{
return match ($i) {
default => 1,
1 => 2,
};
}
echo foo(1); // outputs 2
echo foo(2); // outputs 1https://phpstan.org/r/209f5e83-a76b-4634-b02d-3aeb72a181f6
Expected output
No issue
Actual output
| line | message |
|---|---|
| 9 | Match arm comparison is always true. |
| 10 | Match arm is unreachable because previous comparison is always true. |
cc @iluuu1994 in case I'm misunderstanding this
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels