Skip to content

fix: stop Statement::Variable from consuming sibling args in list context - #435

Draft
toddr-bot wants to merge 2 commits into
masterfrom
koan.toddr.bot/fix-issue-25
Draft

fix: stop Statement::Variable from consuming sibling args in list context#435
toddr-bot wants to merge 2 commits into
masterfrom
koan.toddr.bot/fix-issue-25

Conversation

@toddr-bot

@toddr-bot toddr-bot commented Apr 27, 2026

Copy link
Copy Markdown
Collaborator

Summary

PPI::Statement::Variable was too greedy when appearing inside a function call's argument list. For example, in open(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_statement that 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

  • Add comma-termination logic for PPI::Statement::Variable in simple form inside Lexer::_lex_statement
  • Add tests for variable declarations inside function call argument lists (open(my $fh, ...), foo(our $x, ...), etc.)
  • Add regression tests ensuring top-level declarations with initializers are unchanged

Test plan

  • New tests verify Variable statement contains only the declaration tokens when inside list context
  • All four declaration types tested: my, our, local, state
  • Assignment inside list tested: foo(my $x = 1, $y) correctly keeps my $x = 1
  • Regression tests confirm my $x = 1; and my ($a, $b) = (1, 2); are unaffected
  • Full test suite (53121 tests across 69 files) passes with zero failures

Generated 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

toddr-bot and others added 2 commits April 27, 2026 09:05
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PPI::Statement::Variable too greedy

2 participants