Fix #10859 by using foldr1 while deriving Eq instances
authorChaitanya Koparkar <ckoparkar@gmail.com>
Mon, 27 Aug 2018 12:07:08 +0000 (14:07 +0200)
committerBen Gamari <ben@smart-cactus.org>
Sun, 16 Sep 2018 16:31:17 +0000 (12:31 -0400)
Summary:
Previously, we were using foldl1 instead, which led to the derived
code to be wrongly associated.

Test Plan: ./validate

Reviewers: RyanGlScott, nomeata, simonpj, bgamari

Reviewed By: RyanGlScott, nomeata

Subscribers: rwbarton, carter

GHC Trac Issues: #10859

Differential Revision: https://phabricator.haskell.org/D5104

(cherry picked from commit 2d953a60489ba30433e5f2fe27c50aa9da75f802)

compiler/typecheck/TcGenDeriv.hs

index beaad98..bb7cd9a 100644 (file)
@@ -214,7 +214,9 @@ gen_Eq_binds loc tycon = do
       where
         nested_eq_expr []  [] [] = true_Expr
         nested_eq_expr tys as bs
-          = foldl1 and_Expr (zipWith3Equal "nested_eq" nested_eq tys as bs)
+          = foldr1 and_Expr (zipWith3Equal "nested_eq" nested_eq tys as bs)
+          -- Using 'foldr1' here ensures that the derived code is correctly
+          -- associated. See Trac #10859.
           where
             nested_eq ty a b = nlHsPar (eq_Expr tycon ty (nlHsVar a) (nlHsVar b))