Skip to content
Permalink
Browse files

Fix #1909 - populate var scope if try always leaves

  • Loading branch information...
muglug committed Jul 7, 2019
1 parent 5f8d4ed commit cd715a60fd396f3c5bc212b48a6660157f9f1ab5
Showing with 22 additions and 0 deletions.
  1. +8 −0 src/Psalm/Internal/Analyzer/Statements/Block/TryAnalyzer.php
  2. +14 −0 tests/TryCatchTest.php
@@ -82,6 +82,12 @@ public static function analyze(
return false;
}
$stmt_control_actions = ScopeAnalyzer::getFinalControlActions(
$stmt->stmts,
$codebase->config->exit_functions,
$context->inside_case
);
/** @var array<string, bool> */
$newly_assigned_var_ids = $context->assigned_var_ids;
@@ -369,6 +375,8 @@ function ($fq_catch_class) use ($codebase) {
$context->vars_in_scope[$var_id],
$type
);
} elseif ($stmt_control_actions === [ScopeAnalyzer::ACTION_END]) {
$context->vars_in_scope[$var_id] = $type;
}
}
@@ -218,6 +218,20 @@ function example() : void {
}
ord($str);',
],
'varSetInOnlyCatch' => [
'<?php
try {
if (rand(0, 1)) {
throw new \Exception("Gotcha!");
}
exit;
} catch (\Exception $e) {
$lastException = $e;
}
echo $lastException->getMessage();'
],
];
}

0 comments on commit cd715a6

Please sign in to comment.
You can’t perform that action at this time.