Add ASSERTs to all calls of nameModule
[ghc-hetmet.git] / compiler / typecheck / TcSplice.lhs
index 60d6a6b..7139fa8 100644 (file)
@@ -63,13 +63,19 @@ import Maybe
 import BasicTypes
 import Panic
 import FastString
+import Data.Typeable (cast)
+import Exception
 
 import qualified Language.Haskell.TH as TH
 -- THSyntax gives access to internal functions and data types
 import qualified Language.Haskell.TH.Syntax as TH
 
 import GHC.Exts                ( unsafeCoerce#, Int#, Int(..) )
-import qualified Control.Exception  as Exception( userErrors )
+#if __GLASGOW_HASKELL__ < 609
+import qualified Exception ( userErrors )
+#else
+import System.IO.Error
+#endif
 \end{code}
 
 Note [Template Haskell levels]
@@ -593,10 +599,24 @@ runMeta convert expr
 
        ; case either_tval of
            Right v -> return v
+#if __GLASGOW_HASKELL__ < 609
            Left exn | Just s <- Exception.userErrors exn
                     , s == "IOEnv failure" 
                     -> failM   -- Error already in Tc monad
                     | otherwise -> failWithTc (mk_msg "run" exn)       -- Exception
+#else
+           Left (SomeException exn) ->
+                    case cast exn of
+                    Just (ErrorCall "IOEnv failure") ->
+                        failM -- Error already in Tc monad
+                    _ ->
+                        case cast exn of
+                        Just ioe
+                         | isUserError ioe &&
+                           (ioeGetErrorString ioe == "IOEnv failure") ->
+                            failM -- Error already in Tc monad
+                        _ -> failWithTc (mk_msg "run" exn)     -- Exception
+#endif
         }}}
   where
     mk_msg s exn = vcat [text "Exception when trying to" <+> text s <+> text "compile-time code:",
@@ -920,7 +940,7 @@ reifyName thing
        -- have free variables, we may need to generate NameL's for them.
   where
     name    = getName thing
-    mod     = nameModule name
+    mod     = ASSERT( isExternalName name ) nameModule name
     pkg_str = packageIdString (modulePackageId mod)
     mod_str = moduleNameString (moduleName mod)
     occ_str = occNameString occ