From d296c4bb9a87d277d881117906dfbf565870e099 Mon Sep 17 00:00:00 2001 From: Bruce Weirdan Date: Thu, 21 Jan 2021 00:42:11 +0200 Subject: [PATCH] Add missing dataflow population in array spreads (#5059) Fixes vimeo/psalm#5057 --- .../Statements/Expression/ArrayAnalyzer.php | 24 +++++++++++++++++++ tests/UnusedVariableTest.php | 10 ++++++++ 2 files changed, 34 insertions(+) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/ArrayAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/ArrayAnalyzer.php index 2323e144d..a87cfb4d7 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/ArrayAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/ArrayAnalyzer.php @@ -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; } diff --git a/tests/UnusedVariableTest.php b/tests/UnusedVariableTest.php index bff38743c..af97c8991 100644 --- a/tests/UnusedVariableTest.php +++ b/tests/UnusedVariableTest.php @@ -2182,6 +2182,16 @@ class UnusedVariableTest extends TestCase print_r(...$d); }' ], + 'explicitSpread' => [ + ' [ '