diff --git a/muscript-optimizer/src/main/java/io/gitlab/jfronny/muscript/optimizer/Optimizer.java b/muscript-optimizer/src/main/java/io/gitlab/jfronny/muscript/optimizer/Optimizer.java index c051698..3e1836a 100644 --- a/muscript-optimizer/src/main/java/io/gitlab/jfronny/muscript/optimizer/Optimizer.java +++ b/muscript-optimizer/src/main/java/io/gitlab/jfronny/muscript/optimizer/Optimizer.java @@ -157,9 +157,7 @@ public class Optimizer { case null -> throw new NullPointerException(); case DynamicConditional(var location, BoolLiteral(var location1, var value), var ifTrue, var ifFalse) -> value ? ifTrue : ifFalse; case DynamicConditional(var location, Not(var location1, var inner), var ifTrue, var ifFalse) -> optimize(new DynamicConditional(location, inner, ifFalse, ifTrue)); - case DynamicConditional(var location, var condition, var ifTrue, var ifFalse) -> ifTrue.equals(ifFalse) - ? new ExprGroup(location, extractSideEffects(condition).map(Optimizer::optimize).toList(), ifTrue, null, false) - : new DynamicConditional(location, condition, ifTrue, ifFalse); + case DynamicConditional(var location, var condition, var ifTrue, var ifFalse) when ifTrue.equals(ifFalse) -> new ExprGroup(location, extractSideEffects(condition).map(Optimizer::optimize).toList(), ifTrue, null, false); case GetOrAt(var location, ObjectLiteral l, var nameOrIndex) -> new Get(location, l, asString(nameOrIndex)); case GetOrAt(var location, ListLiteral l, var nameOrIndex) -> new At(location, l, asNumber(nameOrIndex)); case GetOrAt(var location, var left, StringExpr name) -> new Get(location, left, name); @@ -251,9 +249,8 @@ public class Optimizer { case StringConditional(var location, var condition, var ifTrue, var ifFalse) -> extractConditionalSideEffects(location, condition, ifTrue, ifFalse); case Bind(var location, var callable, var parameter) -> Stream.concat(extractSideEffects(callable), extractSideEffects(parameter)); case Call e -> Stream.of(e); - case ExprGroup(var location, var steps, var finish, var packedArgs, var fork) -> fork - ? Stream.of(expr) - : Stream.of(ExprGroup.of(location, steps.stream().flatMap(Optimizer::extractSideEffects).toList())); + case ExprGroup(var location, var steps, var finish, var packedArgs, var fork) when fork -> Stream.of(expr); + case ExprGroup(var location, var steps, var finish, var packedArgs, var fork) -> Stream.of(ExprGroup.of(location, steps.stream().flatMap(Optimizer::extractSideEffects).toList())); case Get(var location, var left, var name) -> Stream.concat(extractSideEffects(left), extractSideEffects(name)); case At(var location, var left, var index) -> Stream.concat(extractSideEffects(left), extractSideEffects(index)); case GetOrAt(var location, var left, var nameOrIndex) -> Stream.concat(extractSideEffects(left), extractSideEffects(nameOrIndex));