add T[] array-type sugar; verify ?T nullable specialization#4
Merged
Conversation
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>
10254e8 to
973788d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The README's Collection.xphp snippet uses
private T[] $items;andpublic function first(): ?T— neither was actually parseable. PHP's type system has noName[]form, so the cleaned source nikic/php-parser sees would error before any of our markers could attach.Lower
Name[](and chainedName[][]…, for any name including type params and class names) to nativearrayinsideXphpSourceParser's source-cleaning pass. Replacement is variable-length but never spans a newline, so line numbers — the key marker resolution uses — stay stable.?Talready worked throughSpecializer'sNamesubstitution (the NullableType wrapper is preserved by nikic's traverser); add coverage that locks the contract — including a runtime reflection assertion that the specializedfirst()reports the concrete class and allowsNull.