Skip to content
This repository was archived by the owner on Aug 3, 2024. It is now read-only.

Commit deddced

Browse files
harpocratesalexbiehl
authored andcommitted
Update the GblRdrEnv when processing modules
Without a complete environment, we will miss some instances that were encountered during typechecking.
1 parent f1a6a6c commit deddced

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

haddock-api/src/Haddock/Interface.hs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ import GHC hiding (verbosity)
5858
import HscTypes
5959
import FastString (unpackFS)
6060
import MonadUtils (liftIO)
61+
import TcRnTypes (tcg_rdr_env)
62+
import RdrName (plusGlobalRdrEnv)
6163

6264
#if defined(mingw32_HOST_OS)
6365
import System.IO
@@ -163,6 +165,18 @@ processModule :: Verbosity -> ModSummary -> [Flag] -> IfaceMap -> InstIfaceMap -
163165
processModule verbosity modsum flags modMap instIfaceMap = do
164166
out verbosity verbose $ "Checking module " ++ moduleString (ms_mod modsum) ++ "..."
165167
tm <- loadModule =<< typecheckModule =<< parseModule modsum
168+
169+
-- We need to modify the interactive context's environment so that when
170+
-- Haddock later looks for instances, it also looks in the modules it
171+
-- encountered while typechecking.
172+
--
173+
-- See https://github.com/haskell/haddock/issues/469.
174+
hsc_env@HscEnv{ hsc_IC = old_IC } <- getSession
175+
let new_rdr_env = tcg_rdr_env . fst . GHC.tm_internals_ $ tm
176+
setSession hsc_env{ hsc_IC = old_IC {
177+
ic_rn_gbl_env = ic_rn_gbl_env old_IC `plusGlobalRdrEnv` new_rdr_env
178+
} }
179+
166180
if not $ isBootSummary modsum then do
167181
out verbosity verbose "Creating interface..."
168182
(interface, msg) <- runWriterGhc $ createInterface tm flags modMap instIfaceMap

0 commit comments

Comments
 (0)