summaryrefslogtreecommitdiff
path: root/testsuite/tests
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2020-10-06 23:39:29 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-10-09 08:52:07 -0400
commitbfdccac6acce84e15292a454d12f4e0d87ef6f10 (patch)
treef9df5be9421346be191c98846181d3382d15262e /testsuite/tests
parentdfaef1cae7a4a0cb8783933274dae7f39d7165a0 (diff)
downloadhaskell-bfdccac6acce84e15292a454d12f4e0d87ef6f10.tar.gz
Fix desugaring of record updates on data families
This fixes a long-standing bug in the desugaring of record updates for data families, when the latter involves a GADT. It's all explained in Note [Update for GADTs] in GHC.HsToCore.Expr. Building the correct cast is surprisingly tricky, as that Note explains. Fixes #18809. The test case (in indexed-types/should_compile/T18809) contains several examples that exercise the dark corners.
Diffstat (limited to 'testsuite/tests')
-rw-r--r--testsuite/tests/indexed-types/should_compile/T18809.hs33
-rw-r--r--testsuite/tests/indexed-types/should_compile/all.T1
2 files changed, 34 insertions, 0 deletions
diff --git a/testsuite/tests/indexed-types/should_compile/T18809.hs b/testsuite/tests/indexed-types/should_compile/T18809.hs
new file mode 100644
index 0000000000..1e56d980f6
--- /dev/null
+++ b/testsuite/tests/indexed-types/should_compile/T18809.hs
@@ -0,0 +1,33 @@
+{-# LANGUAGE GADTs, TypeFamilies #-}
+
+module T18809 where
+
+-- Ordinary
+data F2 s where
+ MkF2 :: { foo2 :: Int } -> F2 s
+
+bar2 :: F2 s -> Int -> F2 s
+bar2 z y = z { foo2 = y }
+
+-- GADT
+data F1 s where
+ MkF1 :: { foo1 :: Int } -> F1 Int
+
+bar1 :: F1 s -> Int -> F1 s
+bar1 z y = z { foo1 = y }
+
+-- Orinary data family
+data family F3 a
+data instance F3 (s,t) where
+ MkF2b :: { foo3 :: Int } -> F3 (s,t)
+
+bar3 :: F3 (s,t) -> Int -> F3 (s,t)
+bar3 z y = z {foo3 = y}
+
+-- GADT + data family
+data family F4 a
+data instance F4 (s,t) where
+ MkF2a :: { foo4 :: Int } -> F4 (Int,t)
+
+bar4 :: F4 (s,t) -> Int -> F4 (s,t)
+bar4 z y = z { foo4 = y}
diff --git a/testsuite/tests/indexed-types/should_compile/all.T b/testsuite/tests/indexed-types/should_compile/all.T
index 21703374b9..8b3dd5e866 100644
--- a/testsuite/tests/indexed-types/should_compile/all.T
+++ b/testsuite/tests/indexed-types/should_compile/all.T
@@ -296,3 +296,4 @@ test('T17056', normal, compile, [''])
test('T17405', normal, multimod_compile, ['T17405c', '-v0'])
test('T17923', normal, compile, [''])
test('T18065', normal, compile, ['-O'])
+test('T18809', normal, compile, ['-O'])