fix: parse $$$a as chained dereferences, not $$ magic + $a - #428
Draft
toddr-bot wants to merge 2 commits into
Draft
fix: parse $$$a as chained dereferences, not $$ magic + $a#428toddr-bot wants to merge 2 commits into
toddr-bot wants to merge 2 commits into
Conversation
$$$a should be parsed as Cast($) + Cast($) + Symbol($a) representing two scalar dereferences, but PPI currently produces Magic($$) + Symbol($a). Add a regression test code/dump pair and TODO tests in ppi_token_magic.t that demonstrate the expected tokenization. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When the tokenizer sees $$, it checks if the character after forms a magic variable. For $$, since $$ is in %MAGIC, it was always classified as Magic. But $$$a should be Cast($) + Cast($) + Symbol($a) — two scalar dereferences. The fix adds a lookahead in Unknown.pm: when $$ is tentatively Magic and the character after is $ followed by a word char or another $, the first $ is instead finalized as a Cast. The second $ then re-enters Unknown resolution and the process recurses correctly for any depth of chained dereferences. This also improves $$0, $$1 etc. which now correctly produce Cast($) + Magic($0) instead of Cast($) + Symbol($0). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.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
$$$awas incorrectly parsed as$$(Magic PID variable) +$a(Symbol), but Perl treats it as${${$a}}— two scalar dereferences. The fix adds a lookahead inToken::Unknownwhen tentatively classifying$$as Magic: if the next character is$followed by a word character or another$, the first$is finalized as a Cast (dereference) instead.Fixes #60
Changes
Unknown.pm's$handler: when$$would be Magic but is followed by$\wor$$$, emit the first$as Cast and re-enter tokenization for the rest52_triple_dollar_deref(code/dump pair)ppi_token_magic.t08_regression.tand25_increment.tTest plan
$$$a = 3;producesCast($) + Cast($) + Symbol($a)ppi_token_magic.tverifies Cast count and Symbol content for$$$a$$foo,$$,$${^MATCH}cases continue to work correctlyGenerated by Kōan /fix
Quality Report
Changes: 6 files changed, 35 insertions(+), 3 deletions(-)
Code scan: clean
Tests: skipped
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline