fix(parser): allow new Foo IDENT => ... indirect-object form#579
Merged
fix(parser): allow new Foo IDENT => ... indirect-object form#579
new Foo IDENT => ... indirect-object form#579Conversation
Commit 668a348 added a check that rejected indirect-object parsing whenever the candidate "class" was unknown and followed by another bareword IDENTIFIER. That correctly disambiguated `myfunc new Foo (4,5)` (where `myfunc` is a known sub) but also wrongly rejected the legitimate top-level form `new HTTP::Request GET => $url`, breaking Log::Log4perl::Config (which uses exactly this idiom). The discriminator is the outer `subExists`: in the buggy case the outer `myfunc` IS a defined sub, while in `new HTTP::Request GET => ...` the outer `new` is not declared and is itself the indirect method. Restrict the new rejection clause to `subExists` so the second case parses as `HTTP::Request->new(GET => $url)` again. Repro before: $ jcpan -t URI::Simple ... Undefined subroutine &Log::Log4perl::Logger::cleanup ... $ jperl -MLog::Log4perl -e 1 syntax error at .../Log/Log4perl/Config.pm line 647, near "::Request GET " After: both run cleanly; `myfunc new Foo (4,5)` still parses as `myfunc(Foo->new(4,5))`. Generated with [Devin](https://app.devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
e74ea5a to
7d3ce70
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.
Summary
Commit 668a348 ("don't greedily consume
newas indirect-object class") introduced a regression that broke the legitimate indirect-object form:This is exactly the syntax used in
Log::Log4perl::Configline 647, so any program that loadedLog::Log4perlfailed to compile — including CPAN itself, which surfaced as a confusing tail-end failure ofjcpan -t <anything>:The actual symptom was a
syntax error ... near "::Request GET "while requiringLog::Log4perl::Config, which then preventedLog::Log4perl::Logger::cleanupfrom being defined when its END block fired.Root cause
The added rejection clause in
SubroutineParser.javafired whenever the candidate "class" was unknown and the next token was an IDENTIFIER. That correctly handledmyfunc new Foo (4,5)(outermyfuncis a known sub) but also wrongly rejected the bare top-level casenew HTTP::Request GET => $urlwhereGETis just the first list-arg.Fix
Restrict the rejection clause to
subExists— i.e. only when the outer call is itself a known subroutine (the original target case). The bare top-levelnew Class IDENT => ...then parses asClass->new(IDENT => ...)again.Test plan
makepasses (all unit tests green)jperl -MLog::Log4perl -e 1no longer errorsjcpan -t URI::Simpleexits 0f new Foo (1)parses asf(Foo->new(1))(verified with a definedfandFoo::newprinting trace output)Generated with Devin