1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Fix #4519 - prevent crash with empty match

This commit is contained in:
Matt Brown 2020-11-09 08:36:59 -05:00 committed by Daniil Gentili
parent e2eee4cb46
commit ec9d8e6700
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
2 changed files with 26 additions and 0 deletions

View File

@ -79,6 +79,20 @@ class MatchAnalyzer
$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;

View File

@ -176,6 +176,18 @@ class MatchTest extends TestCase
false,
'8.0',
],
'noCrashWithEmptyMatch' => [
'<?php
function foo(int $i) {
match ($i) {
};
}',
'error_message' => 'UnhandledMatchCondition',
[],
false,
'8.0',
],
];
}
}