[commit: ghc] master: Repsect the package name when checking for self-import (fb7c311)

git at git.haskell.org git at git.haskell.org
Fri Jan 16 14:17:34 UTC 2015


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/fb7c311711c8851d0de1e40231150ad999ae9c2b/ghc

>---------------------------------------------------------------

commit fb7c311711c8851d0de1e40231150ad999ae9c2b
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?


>---------------------------------------------------------------

fb7c311711c8851d0de1e40231150ad999ae9c2b
 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 5cb7b18..84a56f0 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