1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

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

This commit is contained in:
Brown 2019-11-11 18:24:43 -05:00
parent f22266b2ff
commit da03902f76
2 changed files with 17 additions and 1 deletions

View File

@ -78,8 +78,10 @@ class DoAnalyzer
}
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 @@ class DoAnalyzer
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;
}
}

View File

@ -289,6 +289,18 @@ class TryCatchTest extends TestCase
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));
}'
],
];
}