Skip to content

Commit

Permalink
Fix associativity fix. #136 (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
AttilaMihaly committed Sep 1, 2020
1 parent 109efb5 commit e891495
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Morphir/Elm/Frontend.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions tests/Morphir/Elm/FrontendTests.elm
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@ valueTests =
, "d : Int"
, "d = 4"
, ""
, "e : Int"
, "e = 4"
, ""
, "f : Int"
, "f = 5"
, ""
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit e891495

Please sign in to comment.