mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Fix analysis when there’s a break in a loop after a reassignment
This commit is contained in:
parent
a4b246406c
commit
5351a07cea
@ -451,6 +451,8 @@ class LoopAnalyzer
|
||||
$type,
|
||||
$loop_scope->loop_parent_context->vars_in_scope[$var]
|
||||
);
|
||||
|
||||
$loop_scope->loop_parent_context->possibly_assigned_var_ids[$var] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1057,7 +1057,7 @@ class ForeachTest extends \Psalm\Tests\TestCase
|
||||
}
|
||||
}'
|
||||
],
|
||||
'loopCanUpdateOuter' => [
|
||||
'loopCanUpdateOuterWithoutBreak' => [
|
||||
'<?php
|
||||
/**
|
||||
* @param array<int> $mappings
|
||||
@ -1069,6 +1069,42 @@ class ForeachTest extends \Psalm\Tests\TestCase
|
||||
}
|
||||
}
|
||||
|
||||
if (is_int($id)) {}
|
||||
}'
|
||||
],
|
||||
'loopCanUpdateOuterWithBreak' => [
|
||||
'<?php
|
||||
/**
|
||||
* @param array<int> $mappings
|
||||
*/
|
||||
function foo(string $id, array $mappings) : void {
|
||||
if ($id === "a") {
|
||||
foreach ($mappings as $value) {
|
||||
if (rand(0, 1)) {
|
||||
$id = $value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (is_int($id)) {}
|
||||
}'
|
||||
],
|
||||
'loopCanUpdateOuterWithContinue' => [
|
||||
'<?php
|
||||
/**
|
||||
* @param array<int> $mappings
|
||||
*/
|
||||
function foo(string $id, array $mappings) : void {
|
||||
if ($id === "a") {
|
||||
foreach ($mappings as $value) {
|
||||
if (rand(0, 1)) {
|
||||
$id = $value;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (is_int($id)) {}
|
||||
}'
|
||||
],
|
||||
|
Loading…
Reference in New Issue
Block a user