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:
parent
e2eee4cb46
commit
ec9d8e6700
@ -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;
|
||||
|
@ -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',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user