Skip to content
Permalink
Browse files

Fix handling of do... while vars defined in try

  • Loading branch information
muglug committed Nov 11, 2019
1 parent f22266b commit da03902f761f8e0f1d256c261d075f1f38df3fb8
Showing with 17 additions and 1 deletion.
  1. +5 −1 src/Psalm/Internal/Analyzer/Statements/Block/DoAnalyzer.php
  2. +12 −0 tests/TryCatchTest.php
@@ -78,8 +78,10 @@ public static function analyze(
}
if (isset($do_context->vars_in_scope[$var])) {
if ($do_context->vars_in_scope[$var]->getId() !== $type->getId()) {
if (!$do_context->vars_in_scope[$var]->equals($type)) {
$was_possibly_undefined = $do_context->vars_in_scope[$var]->possibly_undefined_from_try;
$do_context->vars_in_scope[$var] = Type::combineUnionTypes($do_context->vars_in_scope[$var], $type);
$do_context->vars_in_scope[$var]->possibly_undefined_from_try = $was_possibly_undefined;
}
}
}
@@ -144,7 +146,9 @@ function (Clause $c) use ($mixed_var_ids) {
foreach ($do_context->vars_in_scope as $var_id => $type) {
if (isset($context->vars_in_scope[$var_id])) {
$was_possibly_undefined = $type->possibly_undefined_from_try;
$context->vars_in_scope[$var_id] = Type::combineUnionTypes($context->vars_in_scope[$var_id], $type);
$context->vars_in_scope[$var_id]->possibly_undefined_from_try = $was_possibly_undefined;
}
}
@@ -289,6 +289,18 @@ function example() : void {
echo $lastException->getMessage();'
],
'allowDoubleNestedLoop' => [
'<?php
function foo() : void {
do {
try {
do {
$count = rand(0, 10);
} while ($count === 5);
} catch (Exception $e) {}
} while (rand(0, 1));
}'
],
];
}

0 comments on commit da03902

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