Skip to content

Commit 6ce7273

Browse files
committed
Fix backslash operator to use SCALAR context for most operands
The backslash operator (\) was evaluating all non-\& operands in LIST context, which caused issues when creating references to constant subs or other expressions that return scalars. For example, \PVBM where PVBM is a constant sub would evaluate PVBM() in LIST context, returning a RuntimeList, then call createReference() on it which throws 'create reference of list not implemented'. This fix changes the backslash operator to evaluate most operands in SCALAR context (the natural context for creating a reference to a value). LIST context is only used for actual list-producing operations like @ and % variables, or explicit ListNodes. This fixes the remaining failures in t/op/bop.t related to references. Progress on t/op/bop.t: Now passes 313 out of 522 tests (59%)
1 parent f1aebb4 commit 6ce7273

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/main/java/org/perlonjava/codegen/EmitOperator.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,15 @@ static void handleCreateReference(EmitterVisitor emitterVisitor, OperatorNode no
893893
node.operand.accept(emitterVisitor.with(RuntimeContextType.LIST));
894894
}
895895
} else {
896-
node.operand.accept(emitterVisitor.with(RuntimeContextType.LIST));
896+
// For most cases, evaluate in SCALAR context to get a reference to the value
897+
// Only use LIST context for actual list-producing operations
898+
int contextType = RuntimeContextType.SCALAR;
899+
if (node.operand instanceof ListNode ||
900+
(node.operand instanceof OperatorNode op &&
901+
(op.operator.equals("@") || op.operator.equals("%")))) {
902+
contextType = RuntimeContextType.LIST;
903+
}
904+
node.operand.accept(emitterVisitor.with(contextType));
897905
emitterVisitor.ctx.mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL,
898906
"org/perlonjava/runtime/RuntimeBase",
899907
"createReference",

0 commit comments

Comments
 (0)