Use tcRnImports rather than rnImports with GHCi "import" statement: fixes #4832
authorMax Bolingbroke <batterseapower@hotmail.com>
Sun, 3 Apr 2011 15:50:47 +0000 (16:50 +0100)
committerMax Bolingbroke <batterseapower@hotmail.com>
Sun, 3 Apr 2011 15:50:47 +0000 (16:50 +0100)
The bug here was that just using rnImports does not ensure that any dependent
orphan modules are loaded, so instances declared by such modules will not be
usable from the GHCi command line after an "import".

This did not affect the :m syntax because it takes a different code path and
uses getModuleExports directly, which contains its own calls to the orphan-module
loading stuff.

compiler/main/HscMain.lhs
compiler/typecheck/TcRnDriver.lhs

index 09db7a8..09f5130 100644 (file)
@@ -97,7 +97,6 @@ import SrcLoc
 import TcRnDriver
 import TcIface         ( typecheckIface )
 import TcRnMonad
-import RnNames          ( rnImports )
 import IfaceEnv                ( initNameCache )
 import LoadIface       ( ifaceStats, initExternalPackageState )
 import PrelInfo                ( wiredInThings, basicKnownKeyNames )
@@ -306,11 +305,12 @@ hscRnImportDecls
         -> [LImportDecl RdrName]
         -> IO GlobalRdrEnv
 
-hscRnImportDecls hsc_env this_mod import_decls = runHsc hsc_env $ do
-  (_, r, _, _) <- 
-       ioMsgMaybe $ initTc hsc_env HsSrcFile False this_mod $
-          rnImports import_decls
-  return r
+-- It is important that we use tcRnImports instead of calling rnImports directly
+-- because tcRnImports will force-load any orphan modules necessary, making extra
+-- instances/family instances visible (GHC #4832)
+hscRnImportDecls hsc_env this_mod import_decls
+  = runHsc hsc_env $ ioMsgMaybe $ initTc hsc_env HsSrcFile False this_mod $
+          fmap tcg_rdr_env $ tcRnImports hsc_env this_mod import_decls
 
 -- -----------------------------------------------------------------------------
 -- | parse a file, returning the abstract syntax
index 3de19ed..8f9f05c 100644 (file)
@@ -9,7 +9,7 @@ module TcRnDriver (
 #ifdef GHCI
        tcRnStmt, tcRnExpr, tcRnType,
        tcRnLookupRdrName,
-       getModuleExports, 
+       tcRnImports, getModuleExports, 
 #endif
        tcRnLookupName,
        tcRnGetInfo,