diff options
author | Matthew Pickering <matthewtpickering@gmail.com> | 2021-12-06 11:44:18 +0000 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-12-09 04:27:11 -0500 |
commit | 803eefb1109564f4dbabd80721cd45ce7268c4a2 (patch) | |
tree | cc7bcc8ece06758953dbae423ed9553b1f0ab156 /compiler/GHC.hs | |
parent | aafa5079bd49a55f5c71664ddb95ffcb9d8ca102 (diff) | |
download | haskell-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.hs')
-rw-r--r-- | compiler/GHC.hs | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/compiler/GHC.hs b/compiler/GHC.hs index a8e02e60c0..d70ca74d25 100644 --- a/compiler/GHC.hs +++ b/compiler/GHC.hs @@ -1637,7 +1637,7 @@ showRichTokenStream ts = go startLoc ts "" -- using the algorithm that is used for an @import@ declaration. findModule :: GhcMonad m => ModuleName -> Maybe FastString -> m Module findModule mod_name maybe_pkg = do - pkg_qual <- renamePkgQualM maybe_pkg + pkg_qual <- renamePkgQualM mod_name maybe_pkg findQualifiedModule pkg_qual mod_name @@ -1673,11 +1673,11 @@ modNotLoadedError dflags m loc = throwGhcExceptionIO $ CmdLineError $ showSDoc d quotes (ppr (moduleName m)) <+> parens (text (expectJust "modNotLoadedError" (ml_hs_file loc))) -renamePkgQualM :: GhcMonad m => Maybe FastString -> m PkgQual -renamePkgQualM p = withSession $ \hsc_env -> pure (renamePkgQual (hsc_unit_env hsc_env) p) +renamePkgQualM :: GhcMonad m => ModuleName -> Maybe FastString -> m PkgQual +renamePkgQualM mn p = withSession $ \hsc_env -> pure (renamePkgQual (hsc_unit_env hsc_env) mn p) -renameRawPkgQualM :: GhcMonad m => RawPkgQual -> m PkgQual -renameRawPkgQualM p = withSession $ \hsc_env -> pure (renameRawPkgQual (hsc_unit_env hsc_env) p) +renameRawPkgQualM :: GhcMonad m => ModuleName -> RawPkgQual -> m PkgQual +renameRawPkgQualM mn p = withSession $ \hsc_env -> pure (renameRawPkgQual (hsc_unit_env hsc_env) mn p) -- | Like 'findModule', but differs slightly when the module refers to -- a source file, and the file has not been loaded via 'load'. In @@ -1688,7 +1688,7 @@ renameRawPkgQualM p = withSession $ \hsc_env -> pure (renameRawPkgQual (hsc_unit -- lookupModule :: GhcMonad m => ModuleName -> Maybe FastString -> m Module lookupModule mod_name maybe_pkg = do - pkgqual <- renamePkgQualM maybe_pkg + pkgqual <- renamePkgQualM mod_name maybe_pkg lookupQualifiedModule pkgqual mod_name lookupQualifiedModule :: GhcMonad m => PkgQual -> ModuleName -> m Module |