From 576ecd66e6c909bb63a8e106e8fe573cf0d1c358 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Thu, 7 Dec 2023 17:29:22 +0100 Subject: [PATCH] Fix #10460 --- .../Codebase/ConstantTypeResolver.php | 4 ++-- tests/ArrayAssignmentTest.php | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/Psalm/Internal/Codebase/ConstantTypeResolver.php b/src/Psalm/Internal/Codebase/ConstantTypeResolver.php index 866b5180e..4bc718e3e 100644 --- a/src/Psalm/Internal/Codebase/ConstantTypeResolver.php +++ b/src/Psalm/Internal/Codebase/ConstantTypeResolver.php @@ -216,8 +216,8 @@ final class ConstantTypeResolver return new TArray([Type::getArrayKey(), Type::getMixed()]); } - foreach ($spread_array->properties as $spread_array_type) { - $properties[$auto_key++] = $spread_array_type; + foreach ($spread_array->properties as $k => $spread_array_type) { + $properties[is_string($k) ? $k : $auto_key++] = $spread_array_type; } continue; } diff --git a/tests/ArrayAssignmentTest.php b/tests/ArrayAssignmentTest.php index 364b6def3..d016298c4 100644 --- a/tests/ArrayAssignmentTest.php +++ b/tests/ArrayAssignmentTest.php @@ -1280,6 +1280,29 @@ class ArrayAssignmentTest extends TestCase 'ignored_issues' => [], 'php_version' => '8.1', ], + 'constantArraySpreadWithString' => [ + 'code' => ' "a", + "b" => "b", + ]; + } + + class ChildClass extends BaseClass { + public const A = [ + ...parent::KEYS, + "c" => "c", + ]; + } + + $a = ChildClass::A;', + 'assertions' => [ + '$a===' => "array{a: 'a', b: 'b', c: 'c'}", + ], + 'ignored_issues' => [], + 'php_version' => '8.1', + ], 'listPropertyAssignmentAfterIsset' => [ 'code' => '