1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 12:24:49 +01:00
This commit is contained in:
Daniil Gentili 2022-12-18 18:19:22 +01:00
parent 7d95f15e30
commit 2f5d0a4a9f
4 changed files with 26 additions and 1 deletions

View File

@ -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()

View File

@ -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;

View File

@ -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 {

View File

@ -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;