-
-
Notifications
You must be signed in to change notification settings - Fork 946
Closed
Labels
Milestone
Description
Bug report
phpstan doesn't account for break 2 in a do-while loop when reporting unreachable statement errors.
Code snippet that reproduces the problem
https://phpstan.org/r/74a76359-70bf-44b7-88a1-e20fb6313b34
<?php
declare(strict_types=1);
function generateRandomTierForWeapon() : int{
do{
$tier = mt_rand(1, 6); // generate random tier
switch($tier){
case 6:
// tier 6 too high for weapons, try generating
// another random tier value.
break;
default:
break 2;
}
}while(true);
return $tier;
}
echo "Generated tier " . generateRandomTierForWeapon() . PHP_EOL;Expected output
Expected no errors to output as the do-while loop can be broken when the condition $tier !== 6 is satisfied.
Actual output
+--------------------------------------------------------------+
| Line | test.php |
+--------------------------------------------------------------+
| 17 | Unreachable statement - code above always terminates. |
+--------------------------------------------------------------+
Reactions are currently unavailable