Skip to content

Conversation

@fglock
Copy link
Owner

@fglock fglock commented Jan 28, 2026

Problem

  • Array literal slices containing range operators were returning only the first element instead of the full slice
  • Tests 27, 28, and 30 in op/array.t were failing
  • 0 decrement operations were not working correctly

Root Cause

  • The handleArrowArrayDeref method assumed all elements in ArrayLiteralNode were literal values
  • When ranges are used, they become BinaryOperatorNode objects that need evaluation in LIST context
  • RuntimeArraySizeLvalue was missing pre/post decrement implementations

Solution

  1. Array Literal Slice Fix: Added detection for non-literal elements in ArrayLiteralNode
  2. 0 Decrement Fix: Implemented pre/post decrement methods in RuntimeArraySizeLvalue

Changes Made

  • Modified src/main/java/org/perlonjava/codegen/Dereference.java
  • Added methods to src/main/java/org/perlonjava/runtime/RuntimeArraySizeLvalue.java

Test Results

  • Tests 27, 28, and 30 in op/array.t now pass
  • Array literal slices with ranges work correctly
  • 0 decrement operations work correctly

Fixes compilation errors in RuntimeSubroutineArgument where getParent()
and getKey() methods were missing from RuntimeArrayProxyEntry.

This resolves the build regressions without affecting test behavior.
- Fix array literal slices containing range operators (e.g., ('a','b','c')[0..2])
- Add pre/post decrement support for RuntimeArraySizeLvalue (0--)
- Handle non-literal elements in ArrayLiteralNode by routing through slice method
- Fixes failing tests 27, 28, 30 in op/array.t
- Refine the 'literal' check to be more precise about what needs LIST context
- Only ranges (.. operator) and array slices (@) need special handling
- Scalar operations (, , etc.) can use single-element optimization
- This improves performance while maintaining correctness
@fglock fglock closed this Jan 28, 2026
@fglock fglock deleted the fix-array-literal-slice-ranges branch January 28, 2026 09:25
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.

2 participants