Skip to content
Permalink
Browse files

Fix #2546 properly

  • Loading branch information
muglug committed Jan 4, 2020
1 parent fb48db9 commit ba6d0df048a36b1592f2f5e6c37ac97b87f7b192
Showing with 16 additions and 1 deletion.
  1. +3 −1 src/Psalm/Internal/Analyzer/Statements/Block/ForAnalyzer.php
  2. +13 −0 tests/UnusedVariableTest.php
@@ -140,7 +140,9 @@ public static function analyze(

if ($context->collect_references) {
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;
} else {
$context->unreferenced_vars[$var_id] = $locations;
@@ -1379,6 +1379,19 @@ function test(): string {
break;
}'
],
'usedForVariable' => [
'<?php
$a = 0;
for ($i = 0; $i < 1000; $i++) {
if (rand(0, 1)) {
$a = $a + $i;
continue;
}
break;
}
echo $a;'
],
];
}

0 comments on commit ba6d0df

Please sign in to comment.
You can’t perform that action at this time.