From b859fba52d9d1a119c0718695f9ae127c3714fce Mon Sep 17 00:00:00 2001 From: AndrolGenhald Date: Fri, 19 Mar 2021 20:51:36 -0500 Subject: [PATCH] Fix array spread false negative that crashes (fixes #5431, reverts #2852) (#5432) --- src/Psalm/Type/Union.php | 1 + tests/ArrayAssignmentTest.php | 13 +++++++++++++ tests/ArrayFunctionCallTest.php | 16 ---------------- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/Psalm/Type/Union.php b/src/Psalm/Type/Union.php index be5246b60..7db42dccd 100644 --- a/src/Psalm/Type/Union.php +++ b/src/Psalm/Type/Union.php @@ -762,6 +762,7 @@ class Union implements TypeNode || isset($this->types['trait-string']) || isset($this->types['numeric-string']) || isset($this->types['callable-string']) + || isset($this->types['array-key']) || $this->literal_string_types || $this->typed_class_strings; } diff --git a/tests/ArrayAssignmentTest.php b/tests/ArrayAssignmentTest.php index 74932b27c..80b08c8ad 100644 --- a/tests/ArrayAssignmentTest.php +++ b/tests/ArrayAssignmentTest.php @@ -1800,6 +1800,19 @@ class ArrayAssignmentTest extends TestCase }', 'error_message' => 'DuplicateArrayKey' ], + 'unpackArrayWithArrayKeyIntoArray' => [ + ' $data + * @return list + */ + function unpackArray(array $data): array + { + return [...$data]; + }', + 'error_message' => 'DuplicateArrayKey', + ], 'ArrayCreateOffsetObject' => [ ' "a"]; diff --git a/tests/ArrayFunctionCallTest.php b/tests/ArrayFunctionCallTest.php index f06993a62..3f2896a8d 100644 --- a/tests/ArrayFunctionCallTest.php +++ b/tests/ArrayFunctionCallTest.php @@ -1761,22 +1761,6 @@ class ArrayFunctionCallTest extends TestCase 'error_levels' => [], '7.4', ], - 'allowUnpackWithArrayKey' => [ - 'one(), ...$this->two()]; - } - }' - ], 'spliceTurnsintKeyedInputToList' => [ '