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:
parent
16c10c8710
commit
7fad81edac
@ -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;
|
||||||
|
@ -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
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user