Skip to content

Commit

Permalink
Fix #2546 properly
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Jan 4, 2020
1 parent fb48db9 commit ba6d0df
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Psalm/Internal/Analyzer/Statements/Block/ForAnalyzer.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ public static function analyze(


if ($context->collect_references) { if ($context->collect_references) {
foreach ($for_context->unreferenced_vars as $var_id => $locations) { foreach ($for_context->unreferenced_vars as $var_id => $locations) {
if (isset($context->unreferenced_vars[$var_id])) { if (isset($loop_scope->referenced_var_ids[$var_id])) {
$statements_analyzer->registerVariableUses($locations);
} elseif (isset($context->unreferenced_vars[$var_id])) {
$context->unreferenced_vars[$var_id] += $locations; $context->unreferenced_vars[$var_id] += $locations;
} else { } else {
$context->unreferenced_vars[$var_id] = $locations; $context->unreferenced_vars[$var_id] = $locations;
Expand Down
13 changes: 13 additions & 0 deletions tests/UnusedVariableTest.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1379,6 +1379,19 @@ function test(): string {
break; break;
}' }'
], ],
'usedForVariable' => [
'<?php
$a = 0;
for ($i = 0; $i < 1000; $i++) {
if (rand(0, 1)) {
$a = $a + $i;
continue;
}
break;
}
echo $a;'
],
]; ];
} }


Expand Down

0 comments on commit ba6d0df

Please sign in to comment.