summaryrefslogtreecommitdiff
path: root/testsuite/tests/th
diff options
context:
space:
mode:
authorAdam Gundry <adam@well-typed.com>2015-05-04 15:30:37 +0100
committerAdam Gundry <adam@well-typed.com>2015-05-04 15:37:56 +0100
commit4efa421327cf127ebefde59b2eece693e37dc3c6 (patch)
treead98439468450a0d9b39c80d1a8e443e34b0445e /testsuite/tests/th
parent2f6a0ac7061c59ed68a6dd5a2243e3e690acbd5f (diff)
downloadhaskell-4efa421327cf127ebefde59b2eece693e37dc3c6.tar.gz
Permit empty closed type families
Fixes #9840 and #10306, and includes an alternative resolution to #8028. This permits empty closed type families, and documents them in the user guide. It updates the Haddock submodule to support the API change. Test Plan: Added `indexed-types/should_compile/T9840` and updated `indexed-types/should_fail/ClosedFam4` and `th/T8028`. Reviewers: austin, simonpj, goldfire Reviewed By: goldfire Subscribers: bgamari, jstolarek, thomie, goldfire Differential Revision: https://phabricator.haskell.org/D841 GHC Trac Issues: #9840, #10306
Diffstat (limited to 'testsuite/tests/th')
-rw-r--r--testsuite/tests/th/T10306.hs14
-rw-r--r--testsuite/tests/th/T8028.hs14
-rw-r--r--testsuite/tests/th/T8028.stderr4
-rw-r--r--testsuite/tests/th/TH_abstractFamily.hs11
-rw-r--r--testsuite/tests/th/TH_abstractFamily.stderr5
-rw-r--r--testsuite/tests/th/all.T5
6 files changed, 46 insertions, 7 deletions
diff --git a/testsuite/tests/th/T10306.hs b/testsuite/tests/th/T10306.hs
new file mode 100644
index 0000000000..b93114b61c
--- /dev/null
+++ b/testsuite/tests/th/T10306.hs
@@ -0,0 +1,14 @@
+{-# LANGUAGE TemplateHaskell, TypeFamilies #-}
+
+module T10306 where
+
+import Language.Haskell.TH
+import GHC.TypeLits
+
+-- Attempting to reify a built-in type family like (+) previously
+-- caused a crash, because it has no equations
+$(do x <- reify ''(+)
+ case x of
+ FamilyI (ClosedTypeFamilyD _ _ _ []) _ -> return []
+ _ -> error $ show x
+ )
diff --git a/testsuite/tests/th/T8028.hs b/testsuite/tests/th/T8028.hs
index fec993a596..6145428aaf 100644
--- a/testsuite/tests/th/T8028.hs
+++ b/testsuite/tests/th/T8028.hs
@@ -1,7 +1,17 @@
-{-# LANGUAGE TemplateHaskell #-}
+{-# LANGUAGE TemplateHaskell, TypeFamilies #-}
module T8028 where
import T8028a
-$(x) \ No newline at end of file
+import Language.Haskell.TH
+
+$(x)
+
+-- Check that the empty closed type family F produced by $(x) can
+-- subsequently be reified
+$(do f <- reify ''F
+ case f of
+ FamilyI (ClosedTypeFamilyD _ _ _ []) _ -> return []
+ _ -> error $ show f
+ )
diff --git a/testsuite/tests/th/T8028.stderr b/testsuite/tests/th/T8028.stderr
deleted file mode 100644
index 20cf1c7cf2..0000000000
--- a/testsuite/tests/th/T8028.stderr
+++ /dev/null
@@ -1,4 +0,0 @@
-
-T8028.hs:7:3:
- Illegal empty closed type family
- When splicing a TH declaration: type family F_0 where
diff --git a/testsuite/tests/th/TH_abstractFamily.hs b/testsuite/tests/th/TH_abstractFamily.hs
new file mode 100644
index 0000000000..78d7e43931
--- /dev/null
+++ b/testsuite/tests/th/TH_abstractFamily.hs
@@ -0,0 +1,11 @@
+module TH_abstractFamily where
+
+import Language.Haskell.TH
+
+-- Empty closed type families are okay...
+ds1 :: Q [Dec]
+ds1 = [d| type family F a where |]
+
+-- ...but abstract ones should result in a type error
+ds2 :: Q [Dec]
+ds2 = [d| type family G a where .. |]
diff --git a/testsuite/tests/th/TH_abstractFamily.stderr b/testsuite/tests/th/TH_abstractFamily.stderr
new file mode 100644
index 0000000000..c0aa8d274b
--- /dev/null
+++ b/testsuite/tests/th/TH_abstractFamily.stderr
@@ -0,0 +1,5 @@
+
+TH_abstractFamily.hs:11:7:
+ abstract closed type family not (yet) handled by Template Haskell
+ type family G a where
+ ..
diff --git a/testsuite/tests/th/all.T b/testsuite/tests/th/all.T
index 3bc738667d..b7c241990a 100644
--- a/testsuite/tests/th/all.T
+++ b/testsuite/tests/th/all.T
@@ -285,7 +285,7 @@ test('ClosedFam2TH', normal, compile, ['-v0'])
test('T8028',
extra_clean(['T8028a.hi', 'T8028a.o']),
- multimod_compile_fail,
+ multimod_compile,
['T8028', '-v0 ' + config.ghc_th_way_flags])
test('TH_Roles1', normal, compile_fail, ['-v0'])
@@ -360,3 +360,6 @@ test('T8624', normal, run_command, ['$MAKE -s --no-print-directory T8624'])
test('TH_Lift', normal, compile, ['-v0'])
test('T10047', normal, ghci_script, ['T10047.script'])
test('T10019', normal, ghci_script, ['T10019.script'])
+test('T10306', normal, compile, ['-v0'])
+
+test('TH_abstractFamily', normal, compile_fail, [''])