From 399a7bfd11b70deb71a4df8c85b1fc01641aeaa5 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 af763bfb0..efd9ddd06 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/TryAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/TryAnalyzer.php @@ -479,7 +479,7 @@ class TryAnalyzer $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 79cc07261..eee38f7dd 100644 --- a/tests/TryCatchTest.php +++ b/tests/TryCatchTest.php @@ -365,6 +365,13 @@ class TryCatchTest extends TestCase } }' ], + 'suppressUndefinedVarInFinally' => [ + 'end = null; + }', + ], ]; }