@@ -361,6 +361,10 @@ captureSplicesAndDeps TypecheckHelpers{..} env k = do
361
361
#if MIN_VERSION_ghc(9,3,0)
362
362
-- TODO: support backpack
363
363
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
364
368
nodeKeyToInstalledModule (NodeKey_Module (ModNodeKeyWithUid (GWIB mod _) uid)) = Just $ mkModule uid mod
365
369
nodeKeyToInstalledModule _ = Nothing
366
370
moduleToNodeKey :: Module -> NodeKey
@@ -1073,11 +1077,18 @@ mergeEnvs env (ms, deps) extraMods envs = do
1073
1077
combineModules a b
1074
1078
| HsSrcFile <- mi_hsc_src (hm_iface a) = a
1075
1079
| 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
+
1076
1087
concatFC :: FinderCacheState -> [FinderCache ] -> IO FinderCache
1077
1088
concatFC cur xs = do
1078
1089
fcModules <- mapM (readIORef . fcModuleCache) xs
1079
1090
fcFiles <- mapM (readIORef . fcFileCache) xs
1080
- fcModules' <- newIORef $! foldl' (plusInstalledModuleEnv const ) cur fcModules
1091
+ fcModules' <- newIORef $! foldl' (plusInstalledModuleEnv combineModuleLocations ) cur fcModules
1081
1092
fcFiles' <- newIORef $! Map. unions fcFiles
1082
1093
pure $ FinderCache fcModules' fcFiles'
1083
1094
0 commit comments