Skip to content

add T[] array-type sugar; verify ?T nullable specialization#4

Merged
math3usmartins merged 1 commit into
mainfrom
feat/array-type-sugar
May 21, 2026
Merged

add T[] array-type sugar; verify ?T nullable specialization#4
math3usmartins merged 1 commit into
mainfrom
feat/array-type-sugar

Conversation

@math3usmartins

Copy link
Copy Markdown
Member

The README's Collection.xphp snippet uses private T[] $items; and public function first(): ?T — neither was actually parseable. PHP's type system has no Name[] form, so the cleaned source nikic/php-parser sees would error before any of our markers could attach.

Lower Name[] (and chained Name[][]…, for any name including type params and class names) to native array inside XphpSourceParser's source-cleaning pass. Replacement is variable-length but never spans a newline, so line numbers — the key marker resolution uses — stay stable.

?T already worked through Specializer's Name substitution (the NullableType wrapper is preserved by nikic's traverser); add coverage that locks the contract — including a runtime reflection assertion that the specialized first() reports the concrete class and allowsNull.

The README's Collection.xphp snippet uses `private T[] $items;` and
`public function first(): ?T` — neither was actually parseable. PHP's
type system has no `Name[]` form, so the cleaned source nikic/php-parser
sees would error before any of our markers could attach.

Lower `Name[]` (and chained `Name[][]…`, for any name including type
params and class names) to native `array` inside `XphpSourceParser`'s
source-cleaning pass. Replacement is variable-length but never spans a
newline, so line numbers — the key marker resolution uses — stay stable.

`?T` already worked through `Specializer`'s `Name` substitution (the
NullableType wrapper is preserved by nikic's traverser); add coverage
that locks the contract — including a runtime reflection assertion that
the specialized `first()` reports the concrete class and allowsNull.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@math3usmartins math3usmartins force-pushed the feat/array-type-sugar branch from 10254e8 to 973788d Compare May 21, 2026 00:43
@math3usmartins math3usmartins merged commit e50f50c into main May 21, 2026
2 checks passed
@math3usmartins math3usmartins deleted the feat/array-type-sugar branch May 21, 2026 00:50
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