1
0
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:
Matthew Brown 2019-09-29 16:12:52 -04:00
parent 14adc9b491
commit 0f7925e769
2 changed files with 15 additions and 12 deletions

View File

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

View File

@ -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;
}',
],
];
}