Skip to content
Permalink
Browse files

Fix #2546 - ignore vars set inside loop

  • Loading branch information
muglug committed Jan 3, 2020
1 parent b6d5021 commit 4263417ac3fde19a67753cf5ddd1a0069e7801e1
Showing with 25 additions and 0 deletions.
  1. +12 −0 src/Psalm/Internal/Analyzer/StatementsAnalyzer.php
  2. +13 −0 tests/UnusedVariableTest.php
@@ -440,6 +440,12 @@ function ($line) {
$loop_scope->unreferenced_vars[$var_id] = $locations;
}
}

foreach ($loop_scope->unreferenced_vars as $var_id => $locations) {
if (!isset($context->unreferenced_vars[$var_id])) {
$this->registerVariableUses($locations);
}
}
}
}

@@ -538,6 +544,12 @@ function ($line) {
$loop_scope->possibly_unreferenced_vars[$var_id] = $locations;
}
}

foreach ($loop_scope->unreferenced_vars as $var_id => $locations) {
if (!isset($context->unreferenced_vars[$var_id])) {
$this->registerVariableUses($locations);
}
}
}
}

@@ -1366,6 +1366,19 @@ function test(): string {
${$name} = $value;
}'
],
'usedLoopVariable' => [
'<?php
$a = 0;
while (rand(0, 1)) {
if ($a < 20) {
$a = $a + 1;
echo "hello";
continue;
}
echo "goodbye";
break;
}'
],
];
}

0 comments on commit 4263417

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