1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 12:24:49 +01:00

Add missing dataflow population in array spreads (#5059)

Fixes vimeo/psalm#5057
This commit is contained in:
Bruce Weirdan 2021-01-21 00:42:11 +02:00 committed by Daniil Gentili
parent a9235b6ee9
commit 394f7347de
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
2 changed files with 34 additions and 0 deletions

View File

@ -241,6 +241,30 @@ class ArrayAnalyzer
$unpacked_array_type
);
if (($data_flow_graph = $statements_analyzer->data_flow_graph)
&& $data_flow_graph instanceof \Psalm\Internal\Codebase\VariableUseGraph
&& $unpacked_array_type->parent_nodes
) {
$var_location = new CodeLocation($statements_analyzer->getSource(), $item->value);
$new_parent_node = \Psalm\Internal\DataFlow\DataFlowNode::getForAssignment(
'array',
$var_location
);
$data_flow_graph->addNode($new_parent_node);
foreach ($unpacked_array_type->parent_nodes as $parent_node) {
$data_flow_graph->addPath(
$parent_node,
$new_parent_node,
'array-assignment'
);
}
$array_creation_info->parent_taint_nodes += [$new_parent_node->id => $new_parent_node];
}
return;
}

View File

@ -2182,6 +2182,16 @@ class UnusedVariableTest extends TestCase
print_r(...$d);
}'
],
'explicitSpread' => [
'<?php
function f(): array {
$s = [1, 2, 3];
$b = ["a", "b", "c"];
$r = [...$s, ...$b];
return $r;
}'
],
'funcGetArgs' => [
'<?php
function validate(bool $b, bool $c) : void {