[commit: ghc] wip/tc/typeable-with-kinds: Allow `Typeable` instances in interfaces, but warn, and ignore them. (350bda4)

git at git.haskell.org git at git.haskell.org
Sat Mar 7 16:43:31 UTC 2015


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

On branch  : wip/tc/typeable-with-kinds
Link       : http://ghc.haskell.org/trac/ghc/changeset/350bda4cb23b99c75977fd960e6b1bc6b67f5f24/ghc

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

commit 350bda4cb23b99c75977fd960e6b1bc6b67f5f24
Author: Iavor S. Diatchki <diatchki at galois.com>
Date:   Wed Feb 11 10:21:42 2015 -0800

    Allow `Typeable` instances in interfaces, but warn, and ignore them.


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

350bda4cb23b99c75977fd960e6b1bc6b67f5f24
 compiler/typecheck/TcInstDcls.hs | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/compiler/typecheck/TcInstDcls.hs b/compiler/typecheck/TcInstDcls.hs
index 5eb8e5c..b7f2623 100644
--- a/compiler/typecheck/TcInstDcls.hs
+++ b/compiler/typecheck/TcInstDcls.hs
@@ -49,6 +49,7 @@ import BasicTypes
 import DynFlags
 import ErrUtils
 import FastString
+import HscTypes ( isHsBootOrSig )
 import Id
 import MkId
 import Name
@@ -424,6 +425,7 @@ tcInstDecls1 tycl_decls inst_decls deriv_decls
     bad_typeable_instance i
       = typeableClassName == is_cls_nm (iSpec i)
 
+
     overlapCheck ty = case overlapMode (is_flag $ iSpec ty) of
                         NoOverlap _ -> False
                         _           -> True
@@ -433,10 +435,19 @@ tcInstDecls1 tycl_decls inst_decls deriv_decls
                          ptext (sLit "Replace the following instance:"))
                      2 (pprInstanceHdr (iSpec i))
 
-    typeable_err i
-      = setSrcSpan (getSrcSpan (iSpec i)) $
-        addErrTc $ ptext
-          (sLit "Class `Typeable` does not support user-specified instances.")
+    -- Report an error or a warning for a `Typeable` instances.
+    -- If we are workikng on an .hs-boot file, we just report a warning,
+    -- and ignore the instance.  We do this, to give users a chance to fix
+    -- their code.
+    typeable_err i =
+      setSrcSpan (getSrcSpan (iSpec i)) $
+        do env <- getGblEnv
+           if isHsBootOrSig (tcg_src env)
+             then addWarnTc $ vcat
+                  [ ptext (sLit "`Typeable` instances in .hs-boot files are ignored.")
+                  , ptext (sLit "This warning will become an error in future versions of the compiler.")
+                  ]
+             else addErrTc $ ptext (sLit "Class `Typeable` does not support user-specified instances.")
 
 addClsInsts :: [InstInfo Name] -> TcM a -> TcM a
 addClsInsts infos thing_inside



More information about the ghc-commits mailing list