@@ -361,6 +361,10 @@ captureSplicesAndDeps TypecheckHelpers{..} env k = do
361361#if MIN_VERSION_ghc(9,3,0)
362362 -- TODO: support backpack
363363 nodeKeyToInstalledModule :: NodeKey -> Maybe InstalledModule
364+ -- We shouldn't get boot files here, but to be safe, never map them to an installed module
365+ -- because boot files don't have linkables we can load, and we will fail if we try to look
366+ -- for them
367+ nodeKeyToInstalledModule (NodeKey_Module (ModNodeKeyWithUid (GWIB mod IsBoot ) uid)) = Nothing
364368 nodeKeyToInstalledModule (NodeKey_Module (ModNodeKeyWithUid (GWIB mod _) uid)) = Just $ mkModule uid mod
365369 nodeKeyToInstalledModule _ = Nothing
366370 moduleToNodeKey :: Module -> NodeKey
@@ -1073,11 +1077,18 @@ mergeEnvs env (ms, deps) extraMods envs = do
10731077 combineModules a b
10741078 | HsSrcFile <- mi_hsc_src (hm_iface a) = a
10751079 | otherwise = b
1080+
1081+ -- Prefer non-boot files over non-boot files
1082+ -- otherwise we can get errors like https://gitlab.haskell.org/ghc/ghc/-/issues/19816
1083+ -- if a boot file shadows over a non-boot file
1084+ combineModuleLocations a@ (InstalledFound ml m) b | Just fp <- ml_hs_file ml, not (" boot" `isSuffixOf` fp) = a
1085+ combineModuleLocations _ b = b
1086+
10761087 concatFC :: FinderCacheState -> [FinderCache ] -> IO FinderCache
10771088 concatFC cur xs = do
10781089 fcModules <- mapM (readIORef . fcModuleCache) xs
10791090 fcFiles <- mapM (readIORef . fcFileCache) xs
1080- fcModules' <- newIORef $! foldl' (plusInstalledModuleEnv const ) cur fcModules
1091+ fcModules' <- newIORef $! foldl' (plusInstalledModuleEnv combineModuleLocations ) cur fcModules
10811092 fcFiles' <- newIORef $! Map. unions fcFiles
10821093 pure $ FinderCache fcModules' fcFiles'
10831094
0 commit comments