aboutsummaryrefslogtreecommitdiff
path: root/haddock-api/src/Haddock/Interface.hs
diff options
context:
space:
mode:
authorAlec Theriault <alec.theriault@gmail.com>2018-01-15 17:12:18 -0800
committerAlexander Biehl <alexbiehl@gmail.com>2018-02-01 14:58:18 +0100
commitdeddced31cabadf62fe01fff77b094cd005e52a1 (patch)
tree89c7f3423837034e5c937f95b9203adb62dd8773 /haddock-api/src/Haddock/Interface.hs
parentf1a6a6c9c0538fc329054d4fb4d717371d456886 (diff)
Update the GblRdrEnv when processing modules
Without a complete environment, we will miss some instances that were encountered during typechecking.
Diffstat (limited to 'haddock-api/src/Haddock/Interface.hs')
-rw-r--r--haddock-api/src/Haddock/Interface.hs14
1 files changed, 14 insertions, 0 deletions
diff --git a/haddock-api/src/Haddock/Interface.hs b/haddock-api/src/Haddock/Interface.hs
index 20689a8f..cbdf81cb 100644
--- a/haddock-api/src/Haddock/Interface.hs
+++ b/haddock-api/src/Haddock/Interface.hs
@@ -58,6 +58,8 @@ import GHC hiding (verbosity)
import HscTypes
import FastString (unpackFS)
import MonadUtils (liftIO)
+import TcRnTypes (tcg_rdr_env)
+import RdrName (plusGlobalRdrEnv)
#if defined(mingw32_HOST_OS)
import System.IO
@@ -163,6 +165,18 @@ processModule :: Verbosity -> ModSummary -> [Flag] -> IfaceMap -> InstIfaceMap -
processModule verbosity modsum flags modMap instIfaceMap = do
out verbosity verbose $ "Checking module " ++ moduleString (ms_mod modsum) ++ "..."
tm <- loadModule =<< typecheckModule =<< parseModule modsum
+
+ -- We need to modify the interactive context's environment so that when
+ -- Haddock later looks for instances, it also looks in the modules it
+ -- encountered while typechecking.
+ --
+ -- See https://github.com/haskell/haddock/issues/469.
+ hsc_env@HscEnv{ hsc_IC = old_IC } <- getSession
+ let new_rdr_env = tcg_rdr_env . fst . GHC.tm_internals_ $ tm
+ setSession hsc_env{ hsc_IC = old_IC {
+ ic_rn_gbl_env = ic_rn_gbl_env old_IC `plusGlobalRdrEnv` new_rdr_env
+ } }
+
if not $ isBootSummary modsum then do
out verbosity verbose "Creating interface..."
(interface, msg) <- runWriterGhc $ createInterface tm flags modMap instIfaceMap