From 7c222f25d4b2d9f3b149d880f0e1acf8d673e4f5 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Sun, 17 Apr 2016 20:41:47 -0400 Subject: Fixed a bug with arithmetic operators --- .../java/bjc/dicelang/ast/ArithmeticCollapser.java | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'dice-lang/src/main/java/bjc/dicelang/ast/ArithmeticCollapser.java') diff --git a/dice-lang/src/main/java/bjc/dicelang/ast/ArithmeticCollapser.java b/dice-lang/src/main/java/bjc/dicelang/ast/ArithmeticCollapser.java index 5ad0a0f..5c00fe2 100644 --- a/dice-lang/src/main/java/bjc/dicelang/ast/ArithmeticCollapser.java +++ b/dice-lang/src/main/java/bjc/dicelang/ast/ArithmeticCollapser.java @@ -16,8 +16,7 @@ import bjc.utils.funcdata.Tree; * @author ben * */ -final class ArithmeticCollapser - implements IOperatorCollapser { +final class ArithmeticCollapser implements IOperatorCollapser { private OperatorDiceNode type; private BinaryOperator valueOp; @@ -35,12 +34,18 @@ final class ArithmeticCollapser new Pair<>(0, new Tree<>(type)); BinaryOperator>> reducer = - (accumulatedState, currentState) -> { - return reduceStates(accumulatedState, - currentState); + (currentState, accumulatedState) -> { + // Force evaluation of accumulated state to prevent + // certain bugs from occuring + accumulatedState.merge((l, r) -> null); + + return reduceStates(accumulatedState, currentState); }; - return nodes.reduceAux(initState, reducer, (state) -> state); + IPair> reducedState = + nodes.reduceAux(initState, reducer, (state) -> state); + + return reducedState; } private IPair> reduceStates( @@ -52,9 +57,8 @@ final class ArithmeticCollapser .bind((currentValue, currentTree) -> { accumulatedTree.addChild(currentTree); - Integer combinedValue = - valueOp.apply(accumulatedValue, - currentValue); + Integer combinedValue = valueOp.apply( + accumulatedValue, currentValue); return new Pair<>(combinedValue, accumulatedTree); -- cgit v1.2.3