Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #10460 #10464

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Psalm/Internal/Codebase/ConstantTypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ public static function resolve(
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;
}
Expand Down
23 changes: 23 additions & 0 deletions tests/ArrayAssignmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,29 @@ function foo(array $arr) : string {
'ignored_issues' => [],
'php_version' => '8.1',
],
'constantArraySpreadWithString' => [
'code' => '<?php
class BaseClass {
public const KEYS = [
"a" => "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' => '<?php
class Collection {
Expand Down