Skip to content

Commit da001c4

Browse files
authored
Merge pull request #8929 from danog/fix_8923
Fix #8923
2 parents cbf37f7 + 2f5d0a4 commit da001c4

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

src/Psalm/Internal/Analyzer/ScopeAnalyzer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,8 @@ public static function getControlActions(
265265
static fn(string $action): bool => $action !== self::ACTION_NONE
266266
);
267267

268-
if ($stmt instanceof PhpParser\Node\Stmt\While_
268+
if (($stmt instanceof PhpParser\Node\Stmt\While_
269+
|| $stmt instanceof PhpParser\Node\Stmt\Do_)
269270
&& $nodes
270271
&& ($stmt_expr_type = $nodes->getType($stmt->cond))
271272
&& $stmt_expr_type->isAlwaysTruthy()

tests/Loop/DoTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ class DoTest extends TestCase
1616
public function providerValidCodeParse(): iterable
1717
{
1818
return [
19+
'doWhileTrue' => [
20+
'code' => '<?php
21+
function ret(): int {
22+
do {
23+
return 1;
24+
} while (true);
25+
}'
26+
],
1927
'doWhileVar' => [
2028
'code' => '<?php
2129
$worked = false;

tests/Loop/ForTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ class ForTest extends TestCase
1616
public function providerValidCodeParse(): iterable
1717
{
1818
return [
19+
'forTrue' => [
20+
'code' => '<?php
21+
function ret(): int {
22+
for (;;) {
23+
return 1;
24+
}
25+
}'
26+
],
1927
'implicitFourthLoop' => [
2028
'code' => '<?php
2129
function test(): int {

tests/Loop/WhileTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ class WhileTest extends TestCase
1414
public function providerValidCodeParse(): iterable
1515
{
1616
return [
17+
'whileTrue' => [
18+
'code' => '<?php
19+
function ret(): int {
20+
do {
21+
return 1;
22+
} while (true);
23+
}'
24+
],
1725
'whileVar' => [
1826
'code' => '<?php
1927
$worked = false;

0 commit comments

Comments
 (0)