mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Add missing dataflow population in array spreads (#5059)
Fixes vimeo/psalm#5057
This commit is contained in:
parent
592f6794a8
commit
d296c4bb9a
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user