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