From 2f5d0a4a9fd56626d6cf2d258f97be72d19b273b Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sun, 18 Dec 2022 18:19:22 +0100 Subject: [PATCH] Fix #8923 --- src/Psalm/Internal/Analyzer/ScopeAnalyzer.php | 3 ++- tests/Loop/DoTest.php | 8 ++++++++ tests/Loop/ForTest.php | 8 ++++++++ tests/Loop/WhileTest.php | 8 ++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/Psalm/Internal/Analyzer/ScopeAnalyzer.php b/src/Psalm/Internal/Analyzer/ScopeAnalyzer.php index 72af912397a..ad837fe179f 100644 --- a/src/Psalm/Internal/Analyzer/ScopeAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/ScopeAnalyzer.php @@ -265,7 +265,8 @@ public static function getControlActions( static fn(string $action): bool => $action !== self::ACTION_NONE ); - if ($stmt instanceof PhpParser\Node\Stmt\While_ + if (($stmt instanceof PhpParser\Node\Stmt\While_ + || $stmt instanceof PhpParser\Node\Stmt\Do_) && $nodes && ($stmt_expr_type = $nodes->getType($stmt->cond)) && $stmt_expr_type->isAlwaysTruthy() diff --git a/tests/Loop/DoTest.php b/tests/Loop/DoTest.php index d3a436c031f..004a3dcdca6 100644 --- a/tests/Loop/DoTest.php +++ b/tests/Loop/DoTest.php @@ -16,6 +16,14 @@ class DoTest extends TestCase public function providerValidCodeParse(): iterable { return [ + 'doWhileTrue' => [ + 'code' => ' [ 'code' => ' [ + 'code' => ' [ 'code' => ' [ + 'code' => ' [ 'code' => '