Skip to content

Commit b9f5b36

Browse files
committed
Fix pipeline operator when called in a loop
The previous implementation would mutate the expr args, but the expr is shared between the loop iterations, so the second iteration would use the mutated args from the first iteration. Now, it creates a new expr for each iteration.
1 parent 15ff235 commit b9f5b36

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/lit/interpreter.cr

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,10 @@ module Lit
238238

239239
def visit_binary_expr(expr) : Value
240240
if expr.operator.type.pipe_greater?
241-
expr.right.as(Expr::Call).arguments.unshift(expr.left)
242-
return evaluate(expr.right)
241+
right = expr.right.as(Expr::Call)
242+
call = Expr::Call.new(right.callee, right.paren, [expr.left] + right.arguments)
243+
244+
return evaluate(call)
243245
end
244246

245247
left = evaluate(expr.left)

0 commit comments

Comments
 (0)