1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Make sure switch breaks don’t count as loop breaks

This commit is contained in:
Matthew Brown 2018-11-10 16:26:03 -05:00
parent 9f2fe748e8
commit 3664b0975c
2 changed files with 11 additions and 1 deletions

View File

@ -300,7 +300,11 @@ class StatementsChecker extends SourceChecker implements StatementsSource
} elseif ($stmt instanceof PhpParser\Node\Stmt\Break_) {
$loop_scope = $context->loop_scope;
if ($loop_scope && $original_context) {
if ($context->switch_scope && !$stmt->num) {
$loop_scope->final_actions[] = ScopeChecker::ACTION_LEAVE_SWITCH;
} else {
$loop_scope->final_actions[] = ScopeChecker::ACTION_BREAK;
}
$redefined_vars = $context->getRedefinedVars($loop_scope->loop_parent_context->vars_in_scope);

View File

@ -70,6 +70,9 @@ class ForeachTest extends \Psalm\Tests\TestCase
$moo = $foo;
}',
'assertions' => [
'$moo' => 'int',
],
],
'switchVariableWithFallthroughStatement' => [
'<?php
@ -89,6 +92,9 @@ class ForeachTest extends \Psalm\Tests\TestCase
$moo = $foo;
}',
'assertions' => [
'$moo' => 'int',
],
],
'secondLoopWithNotNullCheck' => [
'<?php