diff options
author | Ryan Scott <ryan.gl.scott@gmail.com> | 2018-05-16 12:59:45 -0400 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2018-05-16 12:59:54 -0400 |
commit | 0c7db226012b5cfafc9a38bfe372661672ec8900 (patch) | |
tree | 5bc2e46f8480ee26dfe5fb4657fb8756e5fef5d8 | |
parent | 4ffaf4b67773af4c72d92bb8b6c87b1a7d34ac0f (diff) | |
download | haskell-0c7db226012b5cfafc9a38bfe372661672ec8900.tar.gz |
Fix #15073 by suggesting UnboxedTuples in an error message
Under certain circumstances, `GeneralizedNewtypeDeriving`
can emit code which uses unboxed tuple types, but if `UnboxedTuples`
wasn't enabled, the error message that GHC gave didn't make it very
clear that it could be worked around by explicitly enabling the
extension. Easily fixed.
Test Plan: make test TEST=T15073
Reviewers: bgamari
Reviewed By: bgamari
Subscribers: simonpj, thomie, carter
GHC Trac Issues: #15073
Differential Revision: https://phabricator.haskell.org/D4620
-rw-r--r-- | compiler/typecheck/TcValidity.hs | 5 | ||||
-rw-r--r-- | testsuite/tests/deriving/should_fail/T15073.hs | 8 | ||||
-rw-r--r-- | testsuite/tests/deriving/should_fail/T15073.stderr | 22 | ||||
-rw-r--r-- | testsuite/tests/deriving/should_fail/T15073a.hs | 5 | ||||
-rw-r--r-- | testsuite/tests/deriving/should_fail/all.T | 2 |
5 files changed, 41 insertions, 1 deletions
diff --git a/compiler/typecheck/TcValidity.hs b/compiler/typecheck/TcValidity.hs index 617975ebd3..bdda6cd455 100644 --- a/compiler/typecheck/TcValidity.hs +++ b/compiler/typecheck/TcValidity.hs @@ -621,7 +621,10 @@ forAllEscapeErr env ty tau_kind , text "of kind:" <+> ppr_tidy env tau_kind ]) ) ubxArgTyErr :: TidyEnv -> Type -> (TidyEnv, SDoc) -ubxArgTyErr env ty = (env, sep [text "Illegal unboxed tuple type as function argument:", ppr_tidy env ty]) +ubxArgTyErr env ty + = ( env, vcat [ sep [ text "Illegal unboxed tuple type as function argument:" + , ppr_tidy env ty ] + , text "Perhaps you intended to use UnboxedTuples" ] ) {- Note [Liberal type synonyms] diff --git a/testsuite/tests/deriving/should_fail/T15073.hs b/testsuite/tests/deriving/should_fail/T15073.hs new file mode 100644 index 0000000000..ecceeed5e1 --- /dev/null +++ b/testsuite/tests/deriving/should_fail/T15073.hs @@ -0,0 +1,8 @@ +{-# LANGUAGE GeneralizedNewtypeDeriving #-} +{-# LANGUAGE TypeInType #-} +module T15073 where + +import T15073a + +newtype Foo a = MkFoo a + deriving P diff --git a/testsuite/tests/deriving/should_fail/T15073.stderr b/testsuite/tests/deriving/should_fail/T15073.stderr new file mode 100644 index 0000000000..7658b8e422 --- /dev/null +++ b/testsuite/tests/deriving/should_fail/T15073.stderr @@ -0,0 +1,22 @@ + +T15073.hs:8:12: error: + • Illegal unboxed tuple type as function argument: (# a #) + Perhaps you intended to use UnboxedTuples + • In the expression: + GHC.Prim.coerce + @(a + -> (Unit# a :: TYPE (GHC.Types.TupleRep ((:) GHC.Types.LiftedRep ([] :: [] GHC.Types.RuntimeRep) :: [] GHC.Types.RuntimeRep)))) + @(Foo a + -> (Unit# (Foo a) :: TYPE (GHC.Types.TupleRep ((:) GHC.Types.LiftedRep ([] :: [] GHC.Types.RuntimeRep) :: [] GHC.Types.RuntimeRep)))) + p + In an equation for ‘p’: + p = GHC.Prim.coerce + @(a + -> (Unit# a :: TYPE (GHC.Types.TupleRep ((:) GHC.Types.LiftedRep ([] :: [] GHC.Types.RuntimeRep) :: [] GHC.Types.RuntimeRep)))) + @(Foo a + -> (Unit# (Foo a) :: TYPE (GHC.Types.TupleRep ((:) GHC.Types.LiftedRep ([] :: [] GHC.Types.RuntimeRep) :: [] GHC.Types.RuntimeRep)))) + p + When typechecking the code for ‘p’ + in a derived instance for ‘P (Foo a)’: + To see the code I am typechecking, use -ddump-deriv + In the instance declaration for ‘P (Foo a)’ diff --git a/testsuite/tests/deriving/should_fail/T15073a.hs b/testsuite/tests/deriving/should_fail/T15073a.hs new file mode 100644 index 0000000000..87e7571f50 --- /dev/null +++ b/testsuite/tests/deriving/should_fail/T15073a.hs @@ -0,0 +1,5 @@ +{-# LANGUAGE UnboxedTuples #-} +module T15073a where + +class P a where + p :: a -> (# a #) diff --git a/testsuite/tests/deriving/should_fail/all.T b/testsuite/tests/deriving/should_fail/all.T index 8dc5b780af..f1d8261e4b 100644 --- a/testsuite/tests/deriving/should_fail/all.T +++ b/testsuite/tests/deriving/should_fail/all.T @@ -72,3 +72,5 @@ test('T14365', [extra_files(['T14365B.hs','T14365B.hs-boot'])], test('T14728a', normal, compile_fail, ['']) test('T14728b', normal, compile_fail, ['']) test('T14916', normal, compile_fail, ['']) +test('T15073', [extra_files(['T15073a.hs'])], multimod_compile_fail, + ['T15073', '-v0']) |