1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Fix issue with unset var in loop

This commit is contained in:
Matt Brown 2017-03-15 11:38:23 -04:00
parent 16c10c8710
commit 7fad81edac
2 changed files with 24 additions and 0 deletions

View File

@ -400,6 +400,12 @@ class StatementsChecker extends SourceChecker implements StatementsSource
} }
} }
foreach ($asserted_vars as $var_id) {
if (!isset($loop_context->vars_in_scope[$var_id])) {
$loop_context->vars_in_scope[$var_id] = $pre_loop_context->vars_in_scope[$var_id];
}
}
// if there are no changes to the types, no need to re-examine // if there are no changes to the types, no need to re-examine
if (!$has_changes) { if (!$has_changes) {
break; break;

View File

@ -550,6 +550,24 @@ class LoopScopeTest extends PHPUnit_Framework_TestCase
$file_checker->visitAndAnalyzeMethods(); $file_checker->visitAndAnalyzeMethods();
} }
/**
* @return void
*/
public function testUnsetInLoop()
{
$stmts = self::$parser->parse('<?php
$a = null;
foreach ([1, 2, 3] as $i) {
$a = $i;
unset($i);
}
');
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
$file_checker->visitAndAnalyzeMethods();
}
/** /**
* @return void * @return void
*/ */