From 3deca8f44135bd1a146902f498189af00dd4d7b4 Mon Sep 17 00:00:00 2001 From: Max Bolingbroke Date: Sun, 3 Apr 2011 16:50:47 +0100 Subject: [PATCH] Use tcRnImports rather than rnImports with GHCi "import" statement: fixes #4832 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 | 12 ++++++------ compiler/typecheck/TcRnDriver.lhs | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/compiler/main/HscMain.lhs b/compiler/main/HscMain.lhs index 09db7a8..09f5130 100644 --- a/compiler/main/HscMain.lhs +++ b/compiler/main/HscMain.lhs @@ -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 diff --git a/compiler/typecheck/TcRnDriver.lhs b/compiler/typecheck/TcRnDriver.lhs index 3de19ed..8f9f05c 100644 --- a/compiler/typecheck/TcRnDriver.lhs +++ b/compiler/typecheck/TcRnDriver.lhs @@ -9,7 +9,7 @@ module TcRnDriver ( #ifdef GHCI tcRnStmt, tcRnExpr, tcRnType, tcRnLookupRdrName, - getModuleExports, + tcRnImports, getModuleExports, #endif tcRnLookupName, tcRnGetInfo, -- 1.7.10.4