summaryrefslogtreecommitdiff
path: root/testsuite
diff options
context:
space:
mode:
authorRyan Scott <ryan.gl.scott@gmail.com>2017-10-19 10:21:17 -0400
committerRyan Scott <ryan.gl.scott@gmail.com>2017-10-19 10:21:17 -0400
commit101a8c770b9d3abd57ff289bffea3d838cf25c80 (patch)
tree06a8a10674970562d4d07555f3c51653c5270662 /testsuite
parente023e78bc13ffae168f00a52324fc406a146b40f (diff)
downloadhaskell-101a8c770b9d3abd57ff289bffea3d838cf25c80.tar.gz
Error when deriving instances in hs-boot files
Summary: According to the GHC users' guide, one cannot derive instances for data types in `.hs-boot` files. However, GHC was not enforcing this in practice, which led to #14365. Fix this by actually throwing an error if a derived instance is detected in an `.hs-boot` file (and recommend how to fix it in the error message.) Test Plan: make test TEST=T14365 Reviewers: ezyang, austin, bgamari, simonpj Reviewed By: simonpj Subscribers: simonpj, rwbarton, thomie GHC Trac Issues: #14365 Differential Revision: https://phabricator.haskell.org/D4102
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/tests/deriving/should_fail/T14365.stderr13
-rw-r--r--testsuite/tests/deriving/should_fail/T14365A.hs5
-rw-r--r--testsuite/tests/deriving/should_fail/T14365B.hs4
-rw-r--r--testsuite/tests/deriving/should_fail/T14365B.hs-boot7
-rw-r--r--testsuite/tests/deriving/should_fail/all.T2
-rw-r--r--testsuite/tests/deriving/should_fail/drvfail016.stderr6
6 files changed, 35 insertions, 2 deletions
diff --git a/testsuite/tests/deriving/should_fail/T14365.stderr b/testsuite/tests/deriving/should_fail/T14365.stderr
new file mode 100644
index 0000000000..f8f106fea8
--- /dev/null
+++ b/testsuite/tests/deriving/should_fail/T14365.stderr
@@ -0,0 +1,13 @@
+[1 of 3] Compiling T14365B[boot] ( T14365B.hs-boot, T14365B.o-boot )
+
+T14365B.hs-boot:5:13: error:
+ • Can't make a derived instance of ‘Functor Foo’:
+ Cannot derive instances in hs-boot files
+ Write an instance declaration instead
+ • In the data declaration for ‘Foo’
+
+T14365B.hs-boot:7:1: error:
+ • Can't make a derived instance of ‘Foldable Foo’:
+ Cannot derive instances in hs-boot files
+ Write an instance declaration instead
+ • In the stand-alone deriving instance for ‘Foldable Foo’
diff --git a/testsuite/tests/deriving/should_fail/T14365A.hs b/testsuite/tests/deriving/should_fail/T14365A.hs
new file mode 100644
index 0000000000..e80e7d108a
--- /dev/null
+++ b/testsuite/tests/deriving/should_fail/T14365A.hs
@@ -0,0 +1,5 @@
+module T14365A where
+
+import {-# SOURCE #-} T14365B
+
+main = return ()
diff --git a/testsuite/tests/deriving/should_fail/T14365B.hs b/testsuite/tests/deriving/should_fail/T14365B.hs
new file mode 100644
index 0000000000..596c275410
--- /dev/null
+++ b/testsuite/tests/deriving/should_fail/T14365B.hs
@@ -0,0 +1,4 @@
+module T14365B where
+
+data Foo a = Foo a
+ deriving (Functor)
diff --git a/testsuite/tests/deriving/should_fail/T14365B.hs-boot b/testsuite/tests/deriving/should_fail/T14365B.hs-boot
new file mode 100644
index 0000000000..1dcbc9494c
--- /dev/null
+++ b/testsuite/tests/deriving/should_fail/T14365B.hs-boot
@@ -0,0 +1,7 @@
+{-# LANGUAGE StandaloneDeriving #-}
+module T14365B where
+
+data Foo a
+ deriving (Functor)
+
+deriving instance Foldable Foo
diff --git a/testsuite/tests/deriving/should_fail/all.T b/testsuite/tests/deriving/should_fail/all.T
index 77ce1454cb..1861e6dd0a 100644
--- a/testsuite/tests/deriving/should_fail/all.T
+++ b/testsuite/tests/deriving/should_fail/all.T
@@ -66,3 +66,5 @@ test('T11509_1', [when(doing_ghci(), extra_hc_opts('-fobject-code'))],
test('T12163', normal, compile_fail, [''])
test('T12512', omit_ways(['ghci']), compile_fail, [''])
test('T12801', normal, compile_fail, [''])
+test('T14365', [extra_files(['T14365B.hs','T14365B.hs-boot'])],
+ multimod_compile_fail, ['T14365A',''])
diff --git a/testsuite/tests/deriving/should_fail/drvfail016.stderr b/testsuite/tests/deriving/should_fail/drvfail016.stderr
index 182b74893f..05abbf5bb9 100644
--- a/testsuite/tests/deriving/should_fail/drvfail016.stderr
+++ b/testsuite/tests/deriving/should_fail/drvfail016.stderr
@@ -1,4 +1,6 @@
drvfail016.hs-boot:7:14: error:
- Deriving not permitted in hs-boot file
- Use an instance declaration instead
+ • Can't make a derived instance of ‘Show D’:
+ Cannot derive instances in hs-boot files
+ Write an instance declaration instead
+ • In the data declaration for ‘D’