From d8d17a6587c2403653aba5d8921f34e8bde5eec1 Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Wed, 14 Oct 2020 20:19:48 -0400 Subject: [PATCH] Fix #4327 - make sure loop always returns --- src/Psalm/Internal/Analyzer/ScopeAnalyzer.php | 7 +++-- tests/SwitchTypeTest.php | 31 +++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) 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' + ], ]; } }