fix(parser): do not consume keywords across whitespace in qualified names#613
Merged
fix(parser): do not consume keywords across whitespace in qualified names#613
Conversation
…ames
In real perl, qualified identifiers like %Foo:: cannot contain whitespace
around the :: separator. So "%Foo:: and 2" tokenizes as the stash hash
%Foo:: followed by the low-precedence operator `and`, while "%Foo::and" (no
space) is the hash named "and" in package Foo.
PerlOnJava's IdentifierParser was skipping whitespace immediately after ::
(and after the legacy ' separator), which caused it to greedily pull the
next keyword into the qualified name. As a result, "%Foo:: and 2" was
parsed as "%Foo::and 2" and rejected with a syntax error.
This broke the bundled Dumpvalue.pm at line 110
and %overload:: and defined &{'overload::StrVal'};
which in turn broke any code path that lazily required Dumpvalue. The
user-visible symptom was that CPAN.pm's error reporter (require'd from
CPAN/Shell.pm) failed to compile, so e.g. `jcpan -t JSON::Literal` died
with a confusing parse error instead of the actual CPAN error.
Fix: stop calling Whitespace.skipWhitespace after consuming :: or ' in
parseComplexIdentifierInner. The next token must be flush against the
separator to be treated as a continuation of the qualified name.
Adds a regression test (src/test/resources/unit/stash_var_keyword_op.t)
covering the keyword operators (and / or / xor / not / cmp), the
high-precedence forms (&&, ||) which were already correct, and the
exact Dumpvalue.pm pattern that triggered the original report.
Generated with [Devin](https://cli.devin.ai/docs)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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
Fixes a parser bug where
%Foo:: and 2(and similar) was rejected with a syntax error.In real perl, qualified identifiers cannot contain whitespace around the
::separator. So:%Foo:: and 2→ stash hash%Foo::followed by the low-precedence operatorand%Foo::and→ hash named"and"in packageFoo(no space, single identifier)PerlOnJava's
IdentifierParser.parseComplexIdentifierInnerwas callingWhitespace.skipWhitespaceimmediately after consuming::(and the legacy'separator), which caused it to greedily pull the next keyword across the whitespace into the qualified name. So%Foo:: and 2was parsed as%Foo::and 2and rejected.Why this matters
The bundled
src/main/perl/lib/Dumpvalue.pmline 110 contains:so any code path that loads
Dumpvaluedied at compile time.CPAN.pmlazilyrequires Dumpvalue from its error/dump handler, so the user-visible symptom was that running e.g.died with
syntax error at jar:PERL5LIB/Dumpvalue.pm line 110, near "&"instead of the actual CPAN diagnostic. Reduced repro:Fix
Stop skipping whitespace after
::and'inparseComplexIdentifierInner. The next token must be flush against the separator to be treated as a continuation of the qualified name. Keywords (and,or, etc.) are still allowed inside qualified names when there's no whitespace, e.g.$Foo::and,&UNIVERSAL::isa.Test plan
src/test/resources/unit/stash_var_keyword_op.tcovers:%Foo:: and 1,%Foo:: or ...,%Foo:: xor 0,1 and %Foo:: and 2not %Foo::,1 and %Foo::(trailing stash with no operator)%Foo:: && 1(high-precedence form, regression check — was already OK)keys %Foo::,scalar(keys %Foo::) cmp 0%Foo::and(no space) still resolves to the hash named "and" in Foo$Foo::or(no space) still resolves to the scalar named "or" in Fooand %overload:: and defined ...) compilesmake(full unit test suite) passes./jperl -e 'use Dumpvalue; print "ok\n"'now succeedsGenerated with Devin