1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Improve handling of switch statements with default cases

This commit is contained in:
Matthew Brown 2017-11-20 20:39:27 -05:00
parent f5f7849d3a
commit ad74563327

View File

@ -244,6 +244,15 @@ class SwitchChecker
if ($redefined_vars) {
$context->vars_in_scope = array_merge($context->vars_in_scope, $redefined_vars);
}
if ($possibly_redefined_vars) {
foreach ($possibly_redefined_vars as $var_id => $type) {
if (!isset($redefined_vars[$var_id]) && !isset($new_vars_in_scope[$var_id])) {
$context->vars_in_scope[$var_id]
= Type::combineUnionTypes($type, $context->vars_in_scope[$var_id]);
}
}
}
} elseif ($possibly_redefined_vars) {
foreach ($possibly_redefined_vars as $var_id => $type) {
$context->vars_in_scope[$var_id] = Type::combineUnionTypes($type, $context->vars_in_scope[$var_id]);