Skip to content

Commit

Permalink
Fix vimeo#4519 - prevent crash with empty match
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug authored and danog committed Jan 29, 2021
1 parent e2eee4c commit ec9d8e6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,20 @@ public static function analyze(

$last_arm = array_shift($arms);

if (!$last_arm) {
if (\Psalm\IssueBuffer::accepts(
new UnhandledMatchCondition(
'This match expression does not match anything',
new \Psalm\CodeLocation($statements_analyzer->getSource(), $match_condition)
),
$statements_analyzer->getSuppressedIssues()
)) {
// continue
}

return false;
}

$old_node_data = $statements_analyzer->node_data;

$statements_analyzer->node_data = clone $statements_analyzer->node_data;
Expand Down
12 changes: 12 additions & 0 deletions tests/MatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,18 @@ function foo(int $i) : void {
false,
'8.0',
],
'noCrashWithEmptyMatch' => [
'<?php
function foo(int $i) {
match ($i) {
};
}',
'error_message' => 'UnhandledMatchCondition',
[],
false,
'8.0',
],
];
}
}

0 comments on commit ec9d8e6

Please sign in to comment.