Skip to content

Fix interpreter shift/pop with default @_/@ARGV argument#221

Merged
fglock merged 1 commit into
masterfrom
fix-interpreter-shift-pop-default-array
Feb 23, 2026
Merged

Fix interpreter shift/pop with default @_/@ARGV argument#221
fglock merged 1 commit into
masterfrom
fix-interpreter-shift-pop-default-array

Conversation

@fglock
Copy link
Copy Markdown
Owner

@fglock fglock commented Feb 23, 2026

Problem

shift and pop with no explicit argument failed in interpreter mode:

./jperl --interpreter -E ' say shift ' 123
shift requires array argument at -e line 2, near "say shift "

Root Cause

The parser correctly injects the default array (@main::ARGV at top level, @_ inside a sub) directly as OperatorNode("@", IdentifierNode) on the shift/pop node's operand. However, the bytecode compiler handlers in CompileOperator.java expected the operand to always be wrapped in a ListNode, which is only the case for explicit array arguments like shift \@array.

Fix

Accept operand as either form:

  • OperatorNode("@", ...) directly — default @_/@ARGV case injected by parser
  • ListNode containing OperatorNode("@", ...) — explicit shift \@array case

Verified

say shift                          # 123  (with arg 123)
say pop                            # 123  (with arg 123)
sub foo { say shift } foo("hello") # hello
my @a=(1,2,3); say shift @a; say pop @a  # 1 / 3

The parser injects the default array (e.g. @main::ARGV at top level,
@_ inside a sub) directly as OperatorNode("@", IdentifierNode) on the
shift/pop node's operand. The bytecode compiler handlers were expecting
the operand to always be a ListNode wrapper, causing:

  shift requires array argument at -e line 2, near "say shift"

Fix: accept operand as either:
  - OperatorNode("@", ...) directly  (default @_/@argv case)
  - ListNode containing OperatorNode("@", ...)  (explicit array case)

Verified:
  ./jperl --interpreter -E 'say shift' 123        => 123
  ./jperl --interpreter -E 'say pop' 123          => 123
  sub foo { say shift } foo("hello")              => hello
  my @A=(1,2,3); say shift @A; say pop @A         => 1 / 3
@fglock fglock merged commit 2b4164b into master Feb 23, 2026
2 checks passed
@fglock fglock deleted the fix-interpreter-shift-pop-default-array branch February 23, 2026 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant