diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/TryAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/TryAnalyzer.php index 098e9d492..58399df1a 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/TryAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/TryAnalyzer.php @@ -464,7 +464,7 @@ class TryAnalyzer /** @var string $var_id */ foreach ($finally_context->assigned_var_ids as $var_id => $_) { if (isset($context->vars_in_scope[$var_id]) - && $finally_context->vars_in_scope[$var_id] + && isset($finally_context->vars_in_scope[$var_id]) ) { if ($context->vars_in_scope[$var_id]->possibly_undefined && $context->vars_in_scope[$var_id]->possibly_undefined_from_try diff --git a/tests/PropertyTypeTest.php b/tests/PropertyTypeTest.php index 93173f932..e45b8da02 100644 --- a/tests/PropertyTypeTest.php +++ b/tests/PropertyTypeTest.php @@ -227,6 +227,31 @@ class PropertyTypeTest extends TestCase $this->analyzeFile('somefile.php', new Context()); } + public function testNoCrashInTryCatch(): void + { + Config::getInstance()->remember_property_assignments_after_call = false; + + $this->addFile( + 'somefile.php', + 'f = 1; + maybeMutates(); + } + } + }' + ); + + $this->analyzeFile('somefile.php', new Context()); + } + public function testUniversalObjectCrates(): void { Config::getInstance()->addUniversalObjectCrate(\DateTime::class);