fix: stop Statement::Variable from consuming sibling args in list context - #435
Draft
toddr-bot wants to merge 2 commits into
Draft
fix: stop Statement::Variable from consuming sibling args in list context#435toddr-bot wants to merge 2 commits into
toddr-bot wants to merge 2 commits into
Conversation
Add TODO tests demonstrating that PPI::Statement::Variable consumes tokens beyond the variable declaration when inside a list context. For example, in open(my $fh, ">", $filename), the Variable statement captures all arguments instead of just 'my $fh'. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…text In _lex_statement, add a check that terminates PPI::Statement::Variable at a comma when the declaration is in simple form (keyword + symbol, e.g. 'my $fh'). This prevents the Variable statement from greedily consuming subsequent arguments when it appears inside a function call like open(my $fh, ">", $filename). The fix checks that the Variable has at least 2 significant children and the second is a Symbol (not a Structure::List like 'my ($a, $b)'). Parenthesized declarations and top-level initializers (my $x = 1;) are unaffected. Fixes #25 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
PPI::Statement::Variablewas too greedy when appearing inside a function call's argument list. For example, inopen(my $fh, ">", $filename), the Variable statement consumed all three arguments (my $fh, ">", $filename) instead of just the declaration (my $fh).The fix adds a termination check in
_lex_statementthat ends a Variable statement at a comma when the declaration is in simple form (keyword + symbol). Parenthesized declarations (my ($a, $b)) and top-level initializers (my $x = 1;) are unaffected.Fixes #25
Changes
PPI::Statement::Variablein simple form insideLexer::_lex_statementopen(my $fh, ...),foo(our $x, ...), etc.)Test plan
my,our,local,statefoo(my $x = 1, $y)correctly keepsmy $x = 1my $x = 1;andmy ($a, $b) = (1, 2);are unaffectedGenerated by Kōan /fix
Quality Report
Changes: 2 files changed, 83 insertions(+), 1 deletion(-)
Code scan: clean
Tests: skipped
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline