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' => '