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 72af91239..ad837fe17 100644 --- a/src/Psalm/Internal/Analyzer/ScopeAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/ScopeAnalyzer.php @@ -265,7 +265,8 @@ class ScopeAnalyzer 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 d3a436c03..004a3dcdc 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' => '