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:
parent
9f2fe748e8
commit
3664b0975c
@ -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) {
|
||||
$loop_scope->final_actions[] = ScopeChecker::ACTION_BREAK;
|
||||
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);
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user