Transitively imported instances aren't found
I have three modules:
-
A.hs
defines a typeclassTC
and an instanceTC Int
-
B.hs
importsA
and uses theTC Int
instance -
C.hs
importsB
and uses theTC Int
instance
The problem I am encountering is that B
typechecks, but C
doesn't. I assume it must mean that something from B
is not correctly registered by my usage of the GHC API. If I change C.hs
to directly import A
, then it typechecks.
My full code is in Main.hs
. The function that registers a module after compilation is implemented as follows:
registerModule :: (GhcMonad m) => ModDetails -> ModIface -> m ()
registerModule details@ModDetails{..} iface = do
liftIO . putStrLn $ unwords ["Registering module", moduleNameString . moduleName $ mod]
env <- getSession
env <- return $ extendHpt . addModule $ env
setSession env
where
hmi = HomeModInfo iface details Nothing
mod = mi_module iface
modOrig = ModOrigin (Just True) [] [] True
addModule = modifyUnitState $ \us -> us
{ moduleNameProvidersMap = M.insert (moduleName mod) (M.singleton mod modOrig) $ moduleNameProvidersMap us
}
extendHpt env = env
{ hsc_unit_env = let ue = hsc_unit_env env in ue
{ ue_hpt = addHomeModInfoToHpt hmi (hsc_HPT env)
}
}