1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Fix #270 by looking at root ids when analysing array assignment in loops

This commit is contained in:
Matthew Brown 2017-11-08 08:23:34 -05:00
parent d422bc85d6
commit 44c40dff4f
3 changed files with 25 additions and 25 deletions

View File

@ -27,8 +27,8 @@ class AssignmentMapVisitor extends PhpParser\NodeVisitorAbstract implements PhpP
public function enterNode(PhpParser\Node $node)
{
if ($node instanceof PhpParser\Node\Expr\Assign) {
$left_var_id = ExpressionChecker::getVarId($node->var, $this->this_class_name);
$right_var_id = ExpressionChecker::getVarId($node->expr, $this->this_class_name);
$left_var_id = ExpressionChecker::getRootVarId($node->var, $this->this_class_name);
$right_var_id = ExpressionChecker::getRootVarId($node->expr, $this->this_class_name);
if ($left_var_id) {
$this->assignment_map[$left_var_id][(string)$right_var_id] = true;

View File

@ -464,29 +464,6 @@ class ArrayAssignmentTest extends TestCase
'$e' => 'int',
],
],
'SKIPPED-failingMerge' => [
'<?php
/**
* @param array[][] $args
* @return array[]
*/
function get_merged_dict(array $args) {
$merged = array();
foreach ($args as $group) {
foreach ($group as $key => $value) {
if (isset($merged[$key])) {
$merged[$key] = array_merge($merged[$key], $value);
} else {
$merged[$key] = $value;
}
}
}
return $merged;
}',
],
];
}

View File

@ -335,6 +335,29 @@ class LoopScopeTest extends TestCase
$a->barBar();
}',
],
'loopWithArrayKey' => [
'<?php
/**
* @param array[][] $args
* @return array[]
*/
function get_merged_dict(array $args) {
$merged = array();
foreach ($args as $group) {
foreach ($group as $key => $value) {
if (isset($merged[$key])) {
$merged[$key] = array_merge($merged[$key], $value);
} else {
$merged[$key] = $value;
}
}
}
return $merged;
}',
],
];
}