From e89149596a27125c707308e372670ae6e03ec56d Mon Sep 17 00:00:00 2001 From: Attila Mihaly <60483498+AttilaMihaly@users.noreply.github.com> Date: Tue, 1 Sep 2020 10:36:27 -0400 Subject: [PATCH] Fix associativity fix. #136 (#137) --- src/Morphir/Elm/Frontend.elm | 1 + tests/Morphir/Elm/FrontendTests.elm | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/src/Morphir/Elm/Frontend.elm b/src/Morphir/Elm/Frontend.elm index d7706dea4..fba671adf 100644 --- a/src/Morphir/Elm/Frontend.elm +++ b/src/Morphir/Elm/Frontend.elm @@ -1631,6 +1631,7 @@ fixAssociativity expr = Expression.OperatorApplication o d (Node lr l) (Node _ (Expression.OperatorApplication ro rd (Node rlr rl) (Node rrr rr))) -> if (o == ro) && d == Infix.Left then Expression.OperatorApplication o d (Node (Range.combine [ lr, rlr ]) (Expression.OperatorApplication ro rd (Node lr l) (Node rlr rl))) (Node rrr rr) + |> fixAssociativity else expr diff --git a/tests/Morphir/Elm/FrontendTests.elm b/tests/Morphir/Elm/FrontendTests.elm index 856720107..712cbb333 100644 --- a/tests/Morphir/Elm/FrontendTests.elm +++ b/tests/Morphir/Elm/FrontendTests.elm @@ -267,6 +267,9 @@ valueTests = , "d : Int" , "d = 4" , "" + , "e : Int" + , "e = 4" + , "" , "f : Int" , "f = 5" , "" @@ -357,6 +360,9 @@ valueTests = , checkIR "case a of\n 1 -> foo\n _ -> bar" <| PatternMatch () (ref "a") [ ( LiteralPattern () (IntLiteral 1), ref "foo" ), ( WildcardPattern (), ref "bar" ) ] , checkIR "a <| b" <| Apply () (ref "a") (ref "b") , checkIR "a |> b" <| Apply () (ref "b") (ref "a") + , checkIR "a |> b |> c" <| Apply () (ref "c") (Apply () (ref "b") (ref "a")) + , checkIR "a |> b |> c |> d" <| Apply () (ref "d") (Apply () (ref "c") (Apply () (ref "b") (ref "a"))) + , checkIR "a |> b |> c |> d |> e" <| Apply () (ref "e") (Apply () (ref "d") (Apply () (ref "c") (Apply () (ref "b") (ref "a")))) , checkIR "a || b" <| binary SDKBasics.or (ref "a") (ref "b") , checkIR "a && b" <| binary SDKBasics.and (ref "a") (ref "b") , checkIR "a == b" <| binary SDKBasics.equal (ref "a") (ref "b")