1
0
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:
Brown 2020-09-27 17:50:48 -04:00 committed by Daniil Gentili
parent ecec9dd040
commit cf2872c285
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
2 changed files with 17 additions and 0 deletions

View File

@ -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])

View File

@ -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)) {}
}'
],
]; ];
} }