mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Fix issue when two continue/break statements write same variable
This commit is contained in:
parent
f6e4fb1263
commit
4873f53f69
@ -39,14 +39,7 @@ class BreakAnalyzer
|
||||
$loop_scope->possibly_redefined_loop_parent_vars = $redefined_vars;
|
||||
} else {
|
||||
foreach ($redefined_vars as $var => $type) {
|
||||
if ($type->hasMixed()) {
|
||||
if (isset($loop_scope->possibly_redefined_loop_parent_vars[$var])) {
|
||||
$type->parent_nodes
|
||||
+= $loop_scope->possibly_redefined_loop_parent_vars[$var]->parent_nodes;
|
||||
}
|
||||
|
||||
$loop_scope->possibly_redefined_loop_parent_vars[$var] = $type;
|
||||
} elseif (isset($loop_scope->possibly_redefined_loop_parent_vars[$var])) {
|
||||
if (isset($loop_scope->possibly_redefined_loop_parent_vars[$var])) {
|
||||
$loop_scope->possibly_redefined_loop_parent_vars[$var] = Type::combineUnionTypes(
|
||||
$type,
|
||||
$loop_scope->possibly_redefined_loop_parent_vars[$var]
|
||||
|
@ -75,13 +75,7 @@ class ContinueAnalyzer
|
||||
}
|
||||
|
||||
foreach ($redefined_vars as $var => $type) {
|
||||
if ($type->hasMixed()) {
|
||||
if (isset($loop_scope->possibly_redefined_loop_vars[$var])) {
|
||||
$type->parent_nodes += $loop_scope->possibly_redefined_loop_vars[$var]->parent_nodes;
|
||||
}
|
||||
|
||||
$loop_scope->possibly_redefined_loop_vars[$var] = $type;
|
||||
} elseif (isset($loop_scope->possibly_redefined_loop_vars[$var])) {
|
||||
if (isset($loop_scope->possibly_redefined_loop_vars[$var])) {
|
||||
$loop_scope->possibly_redefined_loop_vars[$var] = Type::combineUnionTypes(
|
||||
$type,
|
||||
$loop_scope->possibly_redefined_loop_vars[$var]
|
||||
|
@ -623,6 +623,27 @@ class WhileTest extends \Psalm\Tests\TestCase
|
||||
return $state;
|
||||
}'
|
||||
],
|
||||
'continueShouldAddToContext' => [
|
||||
'<?php
|
||||
function foo() : void {
|
||||
$link = null;
|
||||
|
||||
while (rand(0, 1)) {
|
||||
if (rand(0, 1)) {
|
||||
$link = "a";
|
||||
continue;
|
||||
}
|
||||
|
||||
if (rand(0, 1)) {
|
||||
if ($link === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user