From 2dc86651a411df6c673079b37df20103705bb4d2 Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Tue, 9 Feb 2021 14:13:18 -0500 Subject: [PATCH] Check context var exists --- .../Internal/Analyzer/Statements/Block/SwitchAnalyzer.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/SwitchAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/SwitchAnalyzer.php index 806fedceb..1ef5d7c27 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/SwitchAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/SwitchAnalyzer.php @@ -197,7 +197,12 @@ class SwitchAnalyzer $stmt->allMatched = true; } elseif ($switch_scope->possibly_redefined_vars) { foreach ($switch_scope->possibly_redefined_vars as $var_id => $type) { - $context->vars_in_scope[$var_id] = Type::combineUnionTypes($type, $context->vars_in_scope[$var_id]); + if (isset($context->vars_in_scope[$var_id])) { + $context->vars_in_scope[$var_id] = Type::combineUnionTypes( + $type, + $context->vars_in_scope[$var_id] + ); + } } }