From 39b85f574b2cb4806a04c46169776b3f55602072 Mon Sep 17 00:00:00 2001 From: orklah Date: Sun, 10 Oct 2021 10:06:37 +0200 Subject: [PATCH] revert back wrong change --- .../Analyzer/Statements/Block/DoAnalyzer.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/DoAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/DoAnalyzer.php index 1902c5785..beae27ba5 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/DoAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/DoAnalyzer.php @@ -92,7 +92,7 @@ class DoAnalyzer if (LoopAnalyzer::analyze( $statements_analyzer, $stmt->stmts, - [$stmt->cond], + WhileAnalyzer::getAndExpressions($stmt->cond), [], $loop_scope, $inner_loop_context, @@ -132,6 +132,22 @@ class DoAnalyzer ); } + foreach ($inner_loop_context->vars_in_scope as $var_id => $type) { + // if there are break statements in the loop it's not certain + // that the loop has finished executing, so the assertions at the end + // the loop in the while conditional may not hold + if (in_array(ScopeAnalyzer::ACTION_BREAK, $loop_scope->final_actions, true)) { + if (isset($loop_scope->possibly_defined_loop_parent_vars[$var_id])) { + $context->vars_in_scope[$var_id] = Type::combineUnionTypes( + $type, + $loop_scope->possibly_defined_loop_parent_vars[$var_id] + ); + } + } else { + $context->vars_in_scope[$var_id] = $type; + } + } + $do_context->loop_scope = null; $context->vars_possibly_in_scope = array_merge(