[Git][ghc/ghc][wip/fendor/26610] Don't lose instances from shadowed imported modules with the same name
Hannes Siebenhandl pushed to branch wip/fendor/26610 at Glasgow Haskell Compiler / GHC Commits: 0aed86e8 by fendor at 2026-09-07T13:22:25+02:00 Don't lose instances from shadowed imported modules with the same name When we look for instances below the current module, we need to check the unit id as well when we check for whether the module is the current module, otherwise we ignore modules we import that have the same name as the import module. Adds regression test. - - - - - 10 changed files: - + changelog.d/26610 - compiler/GHC/Driver/Env.hs - + testsuite/tests/ghci/prog-mhu008/Makefile - + testsuite/tests/ghci/prog-mhu008/a/M.hs - + testsuite/tests/ghci/prog-mhu008/all.T - + testsuite/tests/ghci/prog-mhu008/b/M.hs - + testsuite/tests/ghci/prog-mhu008/prog-mhu008.script - + testsuite/tests/ghci/prog-mhu008/prog-mhu008.stdout - + testsuite/tests/ghci/prog-mhu008/unitA - + testsuite/tests/ghci/prog-mhu008/unitB Changes: ===================================== changelog.d/26610 ===================================== @@ -0,0 +1,7 @@ +section: compiler +synopsis: Fix instance resolution for shadowed modules +description: + Instances imported from modules with the same module name as the importing module + were dropped accidentally since we didn't account for the unit id of the imported module. +mrs: !16648 +issues: #26610 ===================================== compiler/GHC/Driver/Env.hs ===================================== @@ -263,13 +263,13 @@ hugCompleteSigsBelow hsc uid mn = foldr (++) [] <$> -- | Find instances visible from the given set of imports hugInstancesBelow :: HscEnv -> UnitId -> ModuleNameWithIsBoot -> IO (InstEnv, [FamInst]) hugInstancesBelow hsc_env uid mnwib = do - let mn = gwib_mod mnwib + let mn = mkModule uid (gwib_mod mnwib) (insts, famInsts) <- unzip . concat <$> hugSomeThingsBelowUs (\mod_info -> let details = hm_details mod_info -- Don't include instances for the current module - in if moduleName (mi_module (hm_iface mod_info)) == mn + in if fmap toUnitId (mi_module (hm_iface mod_info)) == mn then [] else [(md_insts details, md_fam_insts details)]) True -- Include -hi-boot ===================================== testsuite/tests/ghci/prog-mhu008/Makefile ===================================== @@ -0,0 +1,3 @@ +TOP=../../.. +include $(TOP)/mk/boilerplate.mk +include $(TOP)/mk/test.mk ===================================== testsuite/tests/ghci/prog-mhu008/a/M.hs ===================================== @@ -0,0 +1,4 @@ +module M (T (..)) where + +newtype T = MkT Int + deriving (Eq, Ord) ===================================== testsuite/tests/ghci/prog-mhu008/all.T ===================================== @@ -0,0 +1,5 @@ +test('prog-mhu008', + [extra_files(['a/', 'b/', 'unitA', 'unitB']), + cmd_prefix('ghciWayFlags=' + config.ghci_way_flags), + req_interp], + ghci_multiunit_script, [['unitA', 'unitB'], 'prog-mhu008.script']) ===================================== testsuite/tests/ghci/prog-mhu008/b/M.hs ===================================== @@ -0,0 +1,11 @@ +{-# LANGUAGE PackageImports #-} + +module M + ( module Export + , cmp + ) where + +import "a" M as Export + +cmp :: T -> T -> Bool +cmp x y = x <= y ===================================== testsuite/tests/ghci/prog-mhu008/prog-mhu008.script ===================================== @@ -0,0 +1,5 @@ +:set -XPackageImports +import "a" M qualified as MA +import "b" M qualified as MB + +MB.cmp (MA.MkT 1) (MA.MkT 2) ===================================== testsuite/tests/ghci/prog-mhu008/prog-mhu008.stdout ===================================== @@ -0,0 +1 @@ +True ===================================== testsuite/tests/ghci/prog-mhu008/unitA ===================================== @@ -0,0 +1,5 @@ +-this-unit-id a-0-inplace +-this-package-name a +-i +-ia +M ===================================== testsuite/tests/ghci/prog-mhu008/unitB ===================================== @@ -0,0 +1,6 @@ +-this-unit-id b-0-inplace +-this-package-name b +-package-id a-0-inplace +-i +-ib +M View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/0aed86e8260009266448d2182e79113c... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/0aed86e8260009266448d2182e79113c... You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
participants (1)
-
Hannes Siebenhandl (@fendor)