[commit: ghc] master: Improve error message in deriving( Functor ) (cc92a44)

git at git.haskell.org git at git.haskell.org
Wed Jun 22 21:18:16 UTC 2016


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/cc92a446d6932cf06364529e71c866289088c59a/ghc

>---------------------------------------------------------------

commit cc92a446d6932cf06364529e71c866289088c59a
Author: Simon Peyton Jones <simonpj at microsoft.com>
Date:   Wed Jun 22 14:10:53 2016 +0100

    Improve error message in deriving( Functor )
    
    Fixes Trac #12163.  Pretty simple.


>---------------------------------------------------------------

cc92a446d6932cf06364529e71c866289088c59a
 compiler/typecheck/TcDeriv.hs                          | 13 ++++++++++---
 testsuite/tests/generics/GenCannotDoRep0_0.stderr      |  2 +-
 testsuite/tests/generics/GenCannotDoRep1_0.stderr      | 10 +++++-----
 testsuite/tests/typecheck/should_fail/tcfail086.stderr | 10 +++++-----
 4 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/compiler/typecheck/TcDeriv.hs b/compiler/typecheck/TcDeriv.hs
index 16aecdc..1a93687 100644
--- a/compiler/typecheck/TcDeriv.hs
+++ b/compiler/typecheck/TcDeriv.hs
@@ -1415,12 +1415,19 @@ cond_stdOK Nothing permissive (_, rep_tc)
 
     check_con :: DataCon -> Validity
     check_con con
-      | not (isVanillaDataCon con)
-      = NotValid (badCon con (text "has existentials or constraints in its type"))
+      | not (null eq_spec)
+      = bad "is a GADT"
+      | not (null ex_tvs)
+      = bad "has existential type variables in its type"
+      | not (null theta)
+      = bad "has constraints in its type"
       | not (permissive || all isTauTy (dataConOrigArgTys con))
-      = NotValid (badCon con (text "has a higher-rank type"))
+      = bad "has a higher-rank type"
       | otherwise
       = IsValid
+      where
+        (_, ex_tvs, eq_spec, theta, _, _) = dataConFullSig con
+        bad msg = NotValid (badCon con (text msg))
 
 no_cons_why :: TyCon -> SDoc
 no_cons_why rep_tc = quotes (pprSourceTyCon rep_tc) <+>
diff --git a/testsuite/tests/generics/GenCannotDoRep0_0.stderr b/testsuite/tests/generics/GenCannotDoRep0_0.stderr
index be649e0..02300d4 100644
--- a/testsuite/tests/generics/GenCannotDoRep0_0.stderr
+++ b/testsuite/tests/generics/GenCannotDoRep0_0.stderr
@@ -4,7 +4,7 @@ GenCannotDoRep0_0.hs:6:14: warning:
 
 GenCannotDoRep0_0.hs:13:45: error:
     • Can't make a derived instance of ‘Generic Dynamic’:
-        Constructor ‘Dynamic’ has existentials or constraints in its type
+        Constructor ‘Dynamic’ has existential type variables in its type
         Possible fix: use a standalone deriving declaration instead
     • In the data declaration for ‘Dynamic’
 
diff --git a/testsuite/tests/generics/GenCannotDoRep1_0.stderr b/testsuite/tests/generics/GenCannotDoRep1_0.stderr
index 7764f24..1a576e6 100644
--- a/testsuite/tests/generics/GenCannotDoRep1_0.stderr
+++ b/testsuite/tests/generics/GenCannotDoRep1_0.stderr
@@ -1,6 +1,6 @@
 
-GenCannotDoRep1_0.hs:9:49:
-    Can't make a derived instance of ‘Generic1 Dynamic’:
-      Constructor ‘Dynamic’ has existentials or constraints in its type
-      Possible fix: use a standalone deriving declaration instead
-    In the data declaration for ‘Dynamic’
+GenCannotDoRep1_0.hs:9:49: error:
+    • Can't make a derived instance of ‘Generic1 Dynamic’:
+        Constructor ‘Dynamic’ has existential type variables in its type
+        Possible fix: use a standalone deriving declaration instead
+    • In the data declaration for ‘Dynamic’
diff --git a/testsuite/tests/typecheck/should_fail/tcfail086.stderr b/testsuite/tests/typecheck/should_fail/tcfail086.stderr
index f88fde1..0ea0b71 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail086.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail086.stderr
@@ -1,6 +1,6 @@
 
-tcfail086.hs:6:38:
-    Can't make a derived instance of ‘Eq Ex’:
-      Constructor ‘Ex’ has existentials or constraints in its type
-      Possible fix: use a standalone deriving declaration instead
-    In the data declaration for ‘Ex’
+tcfail086.hs:6:38: error:
+    • Can't make a derived instance of ‘Eq Ex’:
+        Constructor ‘Ex’ has existential type variables in its type
+        Possible fix: use a standalone deriving declaration instead
+    • In the data declaration for ‘Ex’



More information about the ghc-commits mailing list