Skip to content

Name the keys of array shapes that might not be lists with bleeding edge - #7309

Merged
ondrejmirtes merged 1 commit into
2.3.xfrom
describe-maybe-list-shape-keys
Dec 3, 2026
Merged

ondrejmirtes merged 1 commit into
2.3.xfrom
describe-maybe-list-shape-keys

Conversation

@ondrejmirtes

Copy link
Copy Markdown
Member

With bleeding edge, a PHPDoc shape with explicit keys like array{0: string, 1: int} is only maybe a list (cb32a53), but it was still described as array{string, int}, which is how a list shape is written. Downstream projects got self-contradictory errors such as:

Parameter #1 $list of function takesList expects list<int|string>, array{string, int} given.

and the description, pasted back into PHPDoc, meant a different type.

Now a shape with two or more keys that is not surely a list names its keys in describe() and toPhpDocNode():

@return array{0: string, 1: int} @return array{string, int}
bleeding edge array{0: string, 1: int}, rejected for list<…> array{string, int}, accepted
no bleeding edge array{string, int}, accepted array{string, int}, accepted

Shapes that surely are lists keep array{X, Y}, and nothing changes without bleeding edge. The 42 changed expectations are all genuine maybe-lists: arrays after uasort()/uksort(), array{0: …, 1?: …} narrowed by count(), unsealed shapes and localtime()'s non-assoc return.

turbo-ext mirrors the change in ConstantArrayType.cpp; the full suite passes with and without the extension, and signature parity, smoke and side-by-side pass.

With bleeding edge, array{0: string, 1: int} is only maybe a list, but it
was described as array{string, int}, which is the way a list shape is
written. Errors then read "expects list<int|string>, array{string, int}
given", and the description pasted back into a PHPDoc meant a different
type. A shape with two or more keys that is not surely a list now names
its keys in describe() and toPhpDocNode(): array{0: string, 1: int}.
Shapes that surely are lists keep array{string, int}, and nothing changes
without bleeding edge.

turbo-ext: the same in ConstantArrayType.

Amp-Thread-ID: https://ampcode.com/threads/T-01a23bb9-e820-77ee-954b-8a308da670c2
@ondrejmirtes
ondrejmirtes merged commit 794cb69 into 2.3.x Dec 3, 2026
382 of 396 checks passed
@ondrejmirtes
ondrejmirtes deleted the describe-maybe-list-shape-keys branch December 3, 2026 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant