summaryrefslogtreecommitdiff
path: root/compiler/GHC/Rename
diff options
context:
space:
mode:
authorMatthew Pickering <matthewtpickering@gmail.com>2021-12-06 11:44:18 +0000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-12-09 04:27:11 -0500
commit803eefb1109564f4dbabd80721cd45ce7268c4a2 (patch)
treecc7bcc8ece06758953dbae423ed9553b1f0ab156 /compiler/GHC/Rename
parentaafa5079bd49a55f5c71664ddb95ffcb9d8ca102 (diff)
downloadhaskell-803eefb1109564f4dbabd80721cd45ce7268c4a2.tar.gz
package imports: Take into account package visibility when renaming
In 806e49ae the package imports refactoring code was modified to rename package imports. There was a small oversight which meant the code didn't account for module visibility. This patch fixes that oversight. In general the "lookupPackageName" function is unsafe to use as it doesn't account for package visiblity/thinning/renaming etc, there is just one use in the compiler which would be good to audit. Fixes #20779
Diffstat (limited to 'compiler/GHC/Rename')
-rw-r--r--compiler/GHC/Rename/Names.hs14
1 files changed, 7 insertions, 7 deletions
diff --git a/compiler/GHC/Rename/Names.hs b/compiler/GHC/Rename/Names.hs
index 806a9e4dbf..34141ab9f4 100644
--- a/compiler/GHC/Rename/Names.hs
+++ b/compiler/GHC/Rename/Names.hs
@@ -328,7 +328,7 @@ rnImportDecl this_mod
doc = ppr imp_mod_name <+> import_reason
unit_env <- hsc_unit_env <$> getTopEnv
- let pkg_qual = renameRawPkgQual unit_env raw_pkg_qual
+ let pkg_qual = renameRawPkgQual unit_env imp_mod_name raw_pkg_qual
-- Check for self-import, which confuses the typechecker (#9032)
-- ghc --make rejects self-import cycles already, but batch-mode may not
@@ -453,21 +453,21 @@ rnImportDecl this_mod
-- | Rename raw package imports
-renameRawPkgQual :: UnitEnv -> RawPkgQual -> PkgQual
-renameRawPkgQual unit_env = \case
+renameRawPkgQual :: UnitEnv -> ModuleName -> RawPkgQual -> PkgQual
+renameRawPkgQual unit_env mn = \case
NoRawPkgQual -> NoPkgQual
- RawPkgQual p -> renamePkgQual unit_env (Just (sl_fs p))
+ RawPkgQual p -> renamePkgQual unit_env mn (Just (sl_fs p))
-- | Rename raw package imports
-renamePkgQual :: UnitEnv -> Maybe FastString -> PkgQual
-renamePkgQual unit_env mb_pkg = case mb_pkg of
+renamePkgQual :: UnitEnv -> ModuleName -> Maybe FastString -> PkgQual
+renamePkgQual unit_env mn mb_pkg = case mb_pkg of
Nothing -> NoPkgQual
Just pkg_fs
| Just uid <- homeUnitId <$> ue_home_unit unit_env
, pkg_fs == fsLit "this" || pkg_fs == unitFS uid
-> ThisPkg uid
- | Just uid <- lookupPackageName (ue_units unit_env) (PackageName pkg_fs)
+ | Just uid <- resolvePackageImport (ue_units unit_env) mn (PackageName pkg_fs)
-> OtherPkg uid
| otherwise