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 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 && $nodes
&& ($stmt_expr_type = $nodes->getType($stmt->cond)) && ($stmt_expr_type = $nodes->getType($stmt->cond))
&& $stmt_expr_type->isAlwaysTruthy() && $stmt_expr_type->isAlwaysTruthy()

View File

@ -16,6 +16,14 @@ class DoTest extends TestCase
public function providerValidCodeParse(): iterable public function providerValidCodeParse(): iterable
{ {
return [ return [
'doWhileTrue' => [
'code' => '<?php
function ret(): int {
do {
return 1;
} while (true);
}'
],
'doWhileVar' => [ 'doWhileVar' => [
'code' => '<?php 'code' => '<?php
$worked = false; $worked = false;

View File

@ -16,6 +16,14 @@ class ForTest extends TestCase
public function providerValidCodeParse(): iterable public function providerValidCodeParse(): iterable
{ {
return [ return [
'forTrue' => [
'code' => '<?php
function ret(): int {
for (;;) {
return 1;
}
}'
],
'implicitFourthLoop' => [ 'implicitFourthLoop' => [
'code' => '<?php 'code' => '<?php
function test(): int { function test(): int {

View File

@ -14,6 +14,14 @@ class WhileTest extends TestCase
public function providerValidCodeParse(): iterable public function providerValidCodeParse(): iterable
{ {
return [ return [
'whileTrue' => [
'code' => '<?php
function ret(): int {
do {
return 1;
} while (true);
}'
],
'whileVar' => [ 'whileVar' => [
'code' => '<?php 'code' => '<?php
$worked = false; $worked = false;