mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Fix #4327 - make sure loop always returns
This commit is contained in:
parent
c15fabbdcc
commit
84126fbbca
@ -286,8 +286,11 @@ class ScopeAnalyzer
|
||||
|
||||
$control_actions = array_filter(
|
||||
array_merge($control_actions, $do_actions),
|
||||
function ($action) {
|
||||
return $action !== self::ACTION_NONE;
|
||||
function ($action) use ($break_types) {
|
||||
return $action !== self::ACTION_NONE
|
||||
&& ($break_types
|
||||
|| ($action !== self::ACTION_CONTINUE
|
||||
&& $action !== self::ACTION_BREAK));
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@ -999,6 +999,21 @@ class SwitchTypeTest extends TestCase
|
||||
}
|
||||
}'
|
||||
],
|
||||
'loopWithSwitchAlwaysReturns' => [
|
||||
'<?php
|
||||
function b(): int {
|
||||
foreach([1,2] as $i) {
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (random_int(1, 10)) {
|
||||
case 1:
|
||||
return 1;
|
||||
default:
|
||||
return 2;
|
||||
}
|
||||
}',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@ -1270,6 +1285,22 @@ class SwitchTypeTest extends TestCase
|
||||
}',
|
||||
'error_message' => 'ParadoxicalCondition'
|
||||
],
|
||||
'loopWithSwitchDoesntReturnFirstCase' => [
|
||||
'<?php
|
||||
function b(): int {
|
||||
switch (random_int(1, 10)) {
|
||||
case 1:
|
||||
foreach([1,2] as $i) {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
return 2;
|
||||
}
|
||||
}',
|
||||
'error_message' => 'InvalidReturnType'
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user