[commit: ghc] ghc-7.10: Repsect the package name when checking for self-import (b5789df)
git at git.haskell.org
git at git.haskell.org
Fri Jan 16 15:42:39 UTC 2015
Repository : ssh://git@git.haskell.org/ghc
On branch : ghc-7.10
Link : http://ghc.haskell.org/trac/ghc/changeset/b5789dfc0720b1b67d3fdc3c9a77f19011a828d5/ghc
>---------------------------------------------------------------
commit b5789dfc0720b1b67d3fdc3c9a77f19011a828d5
Author: Simon Peyton Jones <simonpj at microsoft.com>
Date: Fri Jan 16 14:17:14 2015 +0000
Repsect the package name when checking for self-import
Fixes Trac #9997.
In doing this I tripped across the specialness of "this" in
PackageImports. The magic constant (fsLit "this") is scattered across
the compiler and ought to be put in one place. But where?
(cherry picked from commit fb7c311711c8851d0de1e40231150ad999ae9c2b)
>---------------------------------------------------------------
b5789dfc0720b1b67d3fdc3c9a77f19011a828d5
compiler/rename/RnNames.hs | 10 +++++++++-
testsuite/tests/module/T9997.hs | 5 +++++
testsuite/tests/module/all.T | 1 +
3 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/compiler/rename/RnNames.hs b/compiler/rename/RnNames.hs
index 145d6fc..b268881 100644
--- a/compiler/rename/RnNames.hs
+++ b/compiler/rename/RnNames.hs
@@ -186,7 +186,15 @@ rnImportDecl this_mod
-- at least not until TcIface.tcHiBootIface, which is too late to avoid
-- typechecker crashes. ToDo: what about indirect self-import?
-- But 'import {-# SOURCE #-} M' is ok, even if a bit odd
- when (not want_boot && imp_mod_name == moduleName this_mod)
+ when (not want_boot &&
+ imp_mod_name == moduleName this_mod &&
+ (case mb_pkg of -- If we have import "<pkg>" M, then we should
+ -- check that "<pkg>" is "this" (which is magic)
+ -- or the name of this_mod's package. Yurgh!
+ -- c.f. GHC.findModule, and Trac #9997
+ Nothing -> True
+ Just pkg_fs -> pkg_fs == fsLit "this" ||
+ fsToPackageKey pkg_fs == modulePackageKey this_mod))
(addErr (ptext (sLit "A module cannot import itself:") <+> ppr imp_mod_name))
-- Check for a missing import list (Opt_WarnMissingImportList also
diff --git a/testsuite/tests/module/T9997.hs b/testsuite/tests/module/T9997.hs
new file mode 100644
index 0000000..acc82da
--- /dev/null
+++ b/testsuite/tests/module/T9997.hs
@@ -0,0 +1,5 @@
+{-# LANGUAGE PackageImports #-}
+module Control.DeepSeq where
+
+import "deepseq" Control.DeepSeq
+
diff --git a/testsuite/tests/module/all.T b/testsuite/tests/module/all.T
index c91d30c..58632be 100644
--- a/testsuite/tests/module/all.T
+++ b/testsuite/tests/module/all.T
@@ -344,3 +344,4 @@ test('T414a', normal, compile, [''])
test('T414b', normal, compile, [''])
test('T3776', normal, compile, [''])
test('T9061', normal, compile, [''])
+test('T9997', normal, compile, [''])
More information about the ghc-commits
mailing list