diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/TryAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/TryAnalyzer.php index 817dec7fa..fe41426c5 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/TryAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/TryAnalyzer.php @@ -353,6 +353,11 @@ class TryAnalyzer } } + $context->vars_possibly_in_scope = array_merge( + $catch_context->vars_possibly_in_scope, + $context->vars_possibly_in_scope + ); + } elseif ($stmt->finally) { $context->vars_possibly_in_scope = array_merge( $catch_context->vars_possibly_in_scope, $context->vars_possibly_in_scope diff --git a/tests/TryCatchTest.php b/tests/TryCatchTest.php index f626f7a78..69f0bb5c5 100644 --- a/tests/TryCatchTest.php +++ b/tests/TryCatchTest.php @@ -181,6 +181,27 @@ class TryCatchTest extends TestCase } }', ], + 'notAlwaysUndefinedVarInFinally' => [ + '