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.
import TcRnDriver
import TcIface ( typecheckIface )
import TcRnMonad
import TcRnDriver
import TcIface ( typecheckIface )
import TcRnMonad
-import RnNames ( rnImports )
import IfaceEnv ( initNameCache )
import LoadIface ( ifaceStats, initExternalPackageState )
import PrelInfo ( wiredInThings, basicKnownKeyNames )
import IfaceEnv ( initNameCache )
import LoadIface ( ifaceStats, initExternalPackageState )
import PrelInfo ( wiredInThings, basicKnownKeyNames )
-> [LImportDecl RdrName]
-> IO GlobalRdrEnv
-> [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
-- -----------------------------------------------------------------------------
-- | parse a file, returning the abstract syntax
#ifdef GHCI
tcRnStmt, tcRnExpr, tcRnType,
tcRnLookupRdrName,
#ifdef GHCI
tcRnStmt, tcRnExpr, tcRnType,
tcRnLookupRdrName,
+ tcRnImports, getModuleExports,
#endif
tcRnLookupName,
tcRnGetInfo,
#endif
tcRnLookupName,
tcRnGetInfo,