Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #8923 #8929

Merged
merged 1 commit into from Dec 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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