Repository navigation
Support trailing comma in closure use list (PHP 8.0) - #8
Merged
Merged
Conversation
function () use ($a, $b,) {} is valid since PHP 8.0 but failed with
"unexpected ')', expecting T_VARIABLE or '&'". The trailing comma is kept
as an extra UseSeparatorTkns entry, like unset(), so printing round-trips.
php8.go regenerated with goyacc from golang.org/x/tools v0.51.0 plus the
Makefile compile seds; newer goyacc emits narrower table types, hence the
size of the generated diff.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BeUiuxXmYgChK2jkSHJYLi
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.
function () use ($a, $b,) {}has been valid since PHP 8.0, but the PHP 8 parser rejects it with:This breaks class-leak's
--blinkmode on rector-src. The first such file (rules/CodeQuality/Rector/Class_/ConvertStaticToSelfRector.php) aborts the whole run.Change
lexical_varsnow acceptspossible_comma. The trailing comma is appended toUseSeparatorTkns, the same wayunset($a, $b,)handles it, so printing reproduces the source exactly.Generated parser
php8.gowas regenerated with goyacc fromgolang.org/x/toolsv0.51.0, then thecompiletarget's seds were applied (yyErrorVerbose = true,// line) andgofmt -s. Every goyacc release from v0.1.12 up emits narrower table types (int16/uint8instead ofint) than the committed file. That's why the generated diff is large: apart from the tables for the new rule, it's type width andint()casts.Tests
TestTrailingCommaInClosureUseList: parses, 2 uses, 2 separator tokens. Fails without the grammar change.TestTrailingCommaInClosureUseListPrintsBack: parses and prints back to the identical source.TestClosureUseListWithoutTrailingCommaStillParsesgo test ./...passes.Note:
parsePHP8inpkg/visitor/printer/printer_php8_test.goactually runs the PHP 7.4 parser, so the new round-trip test lives ininternal/php8instead.Verified end to end: class-leak's Go port built against this branch scans all of rector-src.
🤖 Generated with Claude Code
https://claude.ai/code/session_01BeUiuxXmYgChK2jkSHJYLi