Fix interpreter shift/pop with default @_/@ARGV argument#221
Merged
Conversation
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
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.
Problem
shiftandpopwith no explicit argument failed in interpreter mode:Root Cause
The parser correctly injects the default array (
@main::ARGVat top level,@_inside a sub) directly asOperatorNode("@", IdentifierNode)on theshift/popnode's operand. However, the bytecode compiler handlers inCompileOperator.javaexpected the operand to always be wrapped in aListNode, which is only the case for explicit array arguments likeshift \@array.Fix
Accept operand as either form:
OperatorNode("@", ...)directly — default@_/@ARGVcase injected by parserListNodecontainingOperatorNode("@", ...)— explicitshift \@arraycaseVerified