summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChaitanya Koparkar <ckoparkar@gmail.com>2018-08-27 14:07:08 +0200
committerKrzysztof Gogolewski <krz.gogolewski@gmail.com>2018-08-27 14:07:08 +0200
commit2d953a60489ba30433e5f2fe27c50aa9da75f802 (patch)
tree13c01c51de369cd603bb1fb42f2775f81da36ad8
parent6e765aebbe0a565f2476b522a49faf8edb9a93ee (diff)
downloadhaskell-2d953a60489ba30433e5f2fe27c50aa9da75f802.tar.gz
Fix #10859 by using foldr1 while deriving Eq instances
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
-rw-r--r--compiler/typecheck/TcGenDeriv.hs4
1 files changed, 3 insertions, 1 deletions
diff --git a/compiler/typecheck/TcGenDeriv.hs b/compiler/typecheck/TcGenDeriv.hs
index e74ae32c7a..1debdddd7d 100644
--- a/compiler/typecheck/TcGenDeriv.hs
+++ b/compiler/typecheck/TcGenDeriv.hs
@@ -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))