diff --git a/src/Psalm/Checker/Statements/Block/DoChecker.php b/src/Psalm/Checker/Statements/Block/DoChecker.php index 8b59da32a..cf38f95be 100644 --- a/src/Psalm/Checker/Statements/Block/DoChecker.php +++ b/src/Psalm/Checker/Statements/Block/DoChecker.php @@ -59,6 +59,12 @@ class DoChecker } } + foreach ($do_context->vars_in_scope as $var_id => $type) { + if (!isset($context->vars_in_scope[$var_id])) { + $context->vars_in_scope[$var_id] = clone $type; + } + } + $mixed_var_ids = []; foreach ($do_context->vars_in_scope as $var_id => $type) { diff --git a/tests/LoopScopeTest.php b/tests/LoopScopeTest.php index 21ceb02b3..baf349567 100644 --- a/tests/LoopScopeTest.php +++ b/tests/LoopScopeTest.php @@ -975,6 +975,14 @@ class LoopScopeTest extends TestCase } }', ], + 'doWhileDefinedVar' => [ + '