Skip to content

Commit

Permalink
Merge pull request #8929 from danog/fix_8923
Browse files Browse the repository at this point in the history
Fix #8923
  • Loading branch information
orklah committed Dec 18, 2022
2 parents cbf37f7 + 2f5d0a4 commit da001c4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Psalm/Internal/Analyzer/ScopeAnalyzer.php
Expand Up @@ -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()
Expand Down
8 changes: 8 additions & 0 deletions tests/Loop/DoTest.php
Expand Up @@ -16,6 +16,14 @@ class DoTest extends TestCase
public function providerValidCodeParse(): iterable
{
return [
'doWhileTrue' => [
'code' => '<?php
function ret(): int {
do {
return 1;
} while (true);
}'
],
'doWhileVar' => [
'code' => '<?php
$worked = false;
Expand Down
8 changes: 8 additions & 0 deletions tests/Loop/ForTest.php
Expand Up @@ -16,6 +16,14 @@ class ForTest extends TestCase
public function providerValidCodeParse(): iterable
{
return [
'forTrue' => [
'code' => '<?php
function ret(): int {
for (;;) {
return 1;
}
}'
],
'implicitFourthLoop' => [
'code' => '<?php
function test(): int {
Expand Down
8 changes: 8 additions & 0 deletions tests/Loop/WhileTest.php
Expand Up @@ -14,6 +14,14 @@ class WhileTest extends TestCase
public function providerValidCodeParse(): iterable
{
return [
'whileTrue' => [
'code' => '<?php
function ret(): int {
do {
return 1;
} while (true);
}'
],
'whileVar' => [
'code' => '<?php
$worked = false;
Expand Down

0 comments on commit da001c4

Please sign in to comment.