diff --git a/src/Psalm/Internal/Analyzer/ScopeAnalyzer.php b/src/Psalm/Internal/Analyzer/ScopeAnalyzer.php index c50b67f3e9e..4c431b6a9c1 100644 --- a/src/Psalm/Internal/Analyzer/ScopeAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/ScopeAnalyzer.php @@ -286,8 +286,11 @@ function ($action) { $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)); } ); } diff --git a/tests/SwitchTypeTest.php b/tests/SwitchTypeTest.php index f5421858b44..df6021154a6 100644 --- a/tests/SwitchTypeTest.php +++ b/tests/SwitchTypeTest.php @@ -999,6 +999,21 @@ function getRows(string $s) : int { } }' ], + 'loopWithSwitchAlwaysReturns' => [ + ' 'ParadoxicalCondition' ], + 'loopWithSwitchDoesntReturnFirstCase' => [ + ' 'InvalidReturnType' + ], ]; } }