From cb3a7931c4469f9ce4ddad47d8b1582dad7bcd98 Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Tue, 13 Oct 2020 08:32:26 -0400 Subject: [PATCH] Fix #4315 - prevent crash when setting unknown property in finally --- .../Internal/Analyzer/Statements/Block/TryAnalyzer.php | 2 +- tests/TryCatchTest.php | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/TryAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/TryAnalyzer.php index 8f66d4fb5c1..1dad25426d9 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/TryAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/TryAnalyzer.php @@ -537,7 +537,7 @@ function ($fq_catch_class) use ($codebase): Type\Atomic { $finally_context->vars_in_scope[$var_id], $codebase ); - } else { + } elseif (isset($finally_context->vars_in_scope[$var_id])) { $context->vars_in_scope[$var_id] = clone $finally_context->vars_in_scope[$var_id]; } } diff --git a/tests/TryCatchTest.php b/tests/TryCatchTest.php index 79cc072617a..eee38f7dd08 100644 --- a/tests/TryCatchTest.php +++ b/tests/TryCatchTest.php @@ -365,6 +365,13 @@ class_alias( } }' ], + 'suppressUndefinedVarInFinally' => [ + 'end = null; + }', + ], ]; }