diff --git a/src/Psalm/Checker/Statements/Block/SwitchChecker.php b/src/Psalm/Checker/Statements/Block/SwitchChecker.php index bf634e192..e21a6f44c 100644 --- a/src/Psalm/Checker/Statements/Block/SwitchChecker.php +++ b/src/Psalm/Checker/Statements/Block/SwitchChecker.php @@ -556,14 +556,12 @@ class SwitchChecker if ($redefined_vars !== null) { foreach ($redefined_vars as $var_id => $type) { if (isset($case_context->switch_scope->break_vars[$var_id])) { - if (!isset($case_context->switch_scope->break_vars[$var_id])) { - unset($redefined_vars[$var_id]); - } else { - $redefined_vars[$var_id] = Type::combineUnionTypes( - $case_context->switch_scope->break_vars[$var_id], - $type - ); - } + $redefined_vars[$var_id] = Type::combineUnionTypes( + $case_context->switch_scope->break_vars[$var_id], + $type + ); + } else { + unset($redefined_vars[$var_id]); } } } diff --git a/src/Psalm/Type/Reconciler.php b/src/Psalm/Type/Reconciler.php index 5cd72ab4e..f77dc078b 100644 --- a/src/Psalm/Type/Reconciler.php +++ b/src/Psalm/Type/Reconciler.php @@ -1454,7 +1454,7 @@ class Reconciler $did_remove_type = false; foreach ($existing_var_atomic_types as $atomic_key => $_) { - if ($key !== $new_var_type) { + if ($atomic_key !== $new_var_type) { $existing_var_type->removeType($atomic_key); $did_remove_type = true; } else { @@ -1497,7 +1497,7 @@ class Reconciler $did_remove_type = false; foreach ($existing_var_atomic_types as $atomic_key => $_) { - if ($key !== $new_var_type) { + if ($atomic_key !== $new_var_type) { $existing_var_type->removeType($atomic_key); $did_remove_type = true; } else { @@ -1542,7 +1542,7 @@ class Reconciler $did_remove_type = false; foreach ($existing_var_atomic_types as $atomic_key => $_) { - if ($key !== $new_var_type) { + if ($atomic_key !== $new_var_type) { $existing_var_type->removeType($atomic_key); $did_remove_type = true; } else {