mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Fix #2183 - evaluate return after do with break inside
This commit is contained in:
parent
14adc9b491
commit
0f7925e769
@ -247,20 +247,11 @@ class ScopeAnalyzer
|
||||
}
|
||||
}
|
||||
|
||||
if ($stmt instanceof PhpParser\Node\Stmt\While_) {
|
||||
$control_actions = array_merge(
|
||||
self::getFinalControlActions($stmt->stmts, $exit_functions),
|
||||
$control_actions
|
||||
);
|
||||
}
|
||||
|
||||
if ($stmt instanceof PhpParser\Node\Stmt\Do_) {
|
||||
if ($stmt instanceof PhpParser\Node\Stmt\Do_
|
||||
|| $stmt instanceof PhpParser\Node\Stmt\While_
|
||||
) {
|
||||
$do_actions = self::getFinalControlActions($stmt->stmts, $exit_functions);
|
||||
|
||||
if (count($do_actions) && !in_array(self::ACTION_NONE, $do_actions, true)) {
|
||||
return $do_actions;
|
||||
}
|
||||
|
||||
$control_actions = array_merge($control_actions, $do_actions);
|
||||
}
|
||||
|
||||
|
@ -293,6 +293,18 @@ class DoTest extends \Psalm\Tests\TestCase
|
||||
do {} while (--$i > 0);
|
||||
echo $i === 0;',
|
||||
],
|
||||
'doWhileNonInfinite' => [
|
||||
'<?php
|
||||
function foo(): int {
|
||||
do {
|
||||
$value = mt_rand(0, 10);
|
||||
if ($value > 5) continue;
|
||||
break;
|
||||
} while (true);
|
||||
|
||||
return $value;
|
||||
}',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user