Commit 101a8c77 authored by Ryan Scott's avatar Ryan Scott
Browse files

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
parent e023e78b
......@@ -956,6 +956,10 @@ mkEqnHelp overlap_mode tvs cls cls_tys tycon tc_args mtheta deriv_strat
-- If it's still a data family, the lookup failed; i.e no instance exists
; when (isDataFamilyTyCon rep_tc)
(bale_out (text "No family instance for" <+> quotes (pprTypeApp tycon tc_args)))
; is_boot <- tcIsHsBootOrSig
; when is_boot $
bale_out (text "Cannot derive instances in hs-boot files"
$+$ text "Write an instance declaration instead")
; let deriv_env = DerivEnv
{ denv_overlap_mode = overlap_mode
......
[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’
module T14365A where
import {-# SOURCE #-} T14365B
main = return ()
module T14365B where
data Foo a = Foo a
deriving (Functor)
{-# LANGUAGE StandaloneDeriving #-}
module T14365B where
data Foo a
deriving (Functor)
deriving instance Foldable Foo
......@@ -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',''])
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’
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment