mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
Ensure loop marks vars as possibly assigned
This commit is contained in:
parent
ecec9dd040
commit
cf2872c285
@ -279,6 +279,8 @@ class LoopAnalyzer
|
|||||||
|
|
||||||
// if there's a change, invalidate related clauses
|
// if there's a change, invalidate related clauses
|
||||||
$pre_loop_context->removeVarFromConflictingClauses($var_id);
|
$pre_loop_context->removeVarFromConflictingClauses($var_id);
|
||||||
|
|
||||||
|
$loop_scope->loop_parent_context->possibly_assigned_var_ids[$var_id] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($loop_scope->loop_context->vars_in_scope[$var_id])
|
if (isset($loop_scope->loop_context->vars_in_scope[$var_id])
|
||||||
|
@ -1057,6 +1057,21 @@ class ForeachTest extends \Psalm\Tests\TestCase
|
|||||||
}
|
}
|
||||||
}'
|
}'
|
||||||
],
|
],
|
||||||
|
'loopCanUpdateOuter' => [
|
||||||
|
'<?php
|
||||||
|
/**
|
||||||
|
* @param array<int> $mappings
|
||||||
|
*/
|
||||||
|
function foo(string $id, array $mappings) : void {
|
||||||
|
if ($id === "a") {
|
||||||
|
foreach ($mappings as $value) {
|
||||||
|
$id = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_int($id)) {}
|
||||||
|
}'
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user