1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

flag the context as "inside_conditional" when analyzing leftover cases to prevent emitting unused error

This commit is contained in:
orklah 2021-12-22 21:47:28 +01:00
parent db82095dd2
commit 2c9541c1ed
2 changed files with 18 additions and 0 deletions

View File

@ -320,12 +320,18 @@ class SwitchCaseAnalyzer
);
if ($new_case_equality_expr) {
$was_inside_conditional = $case_context->inside_conditional;
$case_context->inside_conditional = true;
ExpressionAnalyzer::analyze(
$statements_analyzer,
$new_case_equality_expr->getArgs()[1]->value,
$case_context
);
$case_context->inside_conditional = $was_inside_conditional;
$case_equality_expr = $new_case_equality_expr;
}
}

View File

@ -1075,6 +1075,18 @@ class SwitchTypeTest extends TestCase
throw new Exception();
}'
],
'switchWithLeftoverFunctionCallUsesTheFunction' => [
'<?php
function bar (string $name): int {
switch ($name) {
case "a":
case ucfirst("a"):
return 1;
}
return -1;
}'
],
];
}