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

Add foreach possibly-in-scope vars back

This commit is contained in:
Matthew Brown 2016-06-20 16:30:31 -04:00
parent f60e23a7c7
commit 2dc64aafe3
2 changed files with 6 additions and 2 deletions

View File

@ -8,6 +8,8 @@ class Context
public $vars_possibly_in_scope = [];
public $in_loop = false;
public function __clone()
{
foreach ($this->vars_in_scope as $key => &$type) {

View File

@ -1189,6 +1189,7 @@ class StatementsChecker
protected function _checkFor(PhpParser\Node\Stmt\For_ $stmt, Context $context)
{
$for_context = clone $context;
$for_context->in_loop = true;
foreach ($stmt->init as $init) {
if ($this->_checkExpression($init, $for_context) === false) {
@ -1208,7 +1209,7 @@ class StatementsChecker
}
}
$this->check($stmt->stmts, $for_context);
$this->check($stmt->stmts, $for_context, $for_context->vars_possibly_in_scope);
foreach ($context->vars_in_scope as $var => $type) {
if ($type->isMixed()) {
@ -1234,6 +1235,7 @@ class StatementsChecker
}
$foreach_context = clone $context;
$foreach_context->in_loop = true;
if ($stmt->keyVar) {
$foreach_context->vars_in_scope[$stmt->keyVar->name] = Type::getMixed();
@ -1293,7 +1295,7 @@ class StatementsChecker
$this->registerVariable($stmt->valueVar->name, $stmt->getLine());
}
$this->check($stmt->stmts, $foreach_context);
$this->check($stmt->stmts, $foreach_context, $foreach_context->vars_possibly_in_scope);
foreach ($context->vars_in_scope as $var => $type) {
if ($type->isMixed()) {