[commit: ghc] ghc-7.10: Give a hint when a TH splice has a bad package key, partially fixes #10279 (e59fe3e)

git at git.haskell.org git at git.haskell.org
Thu Jun 4 19:55:27 UTC 2015


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

On branch  : ghc-7.10
Link       : http://ghc.haskell.org/trac/ghc/changeset/e59fe3ee5a302a0975c1d4912f799844e9f22e50/ghc

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

commit e59fe3ee5a302a0975c1d4912f799844e9f22e50
Author: Edward Z. Yang <ezyang at cs.stanford.edu>
Date:   Mon Apr 20 14:02:36 2015 -0700

    Give a hint when a TH splice has a bad package key, partially fixes #10279
    
    Previously, if we got a package key in our splice, we'd give
    a very unhelpful error message saying we couldn't find
    a package 'base-4.7.0.1', despite there being a package with
    that source package ID.  Really, we couldn't find a package with
    that *key*, so clarify, and also tell the user what the real
    package key is.
    
    Signed-off-by: Edward Z. Yang <ezyang at cs.stanford.edu>
    (cherry picked from commit bf4f3e653407d02593a69618fb199b2e2d529c92)


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

e59fe3ee5a302a0975c1d4912f799844e9f22e50
 compiler/main/Finder.hs          | 16 ++++++++++++++--
 testsuite/tests/th/T10279.hs     | 10 ++++++++++
 testsuite/tests/th/T10279.stderr |  8 ++++++++
 testsuite/tests/th/all.T         |  1 +
 4 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/compiler/main/Finder.hs b/compiler/main/Finder.hs
index 71b4e97..09bf830 100644
--- a/compiler/main/Finder.hs
+++ b/compiler/main/Finder.hs
@@ -590,8 +590,8 @@ cantFindErr cannot_find _ dflags mod_name find_result
     more_info
       = case find_result of
             NoPackage pkg
-                -> ptext (sLit "no package matching") <+> quotes (ppr pkg) <+>
-                   ptext (sLit "was found")
+                -> ptext (sLit "no package key matching") <+> quotes (ppr pkg) <+>
+                   ptext (sLit "was found") $$ looks_like_srcpkgid pkg
 
             NotFound { fr_paths = files, fr_pkg = mb_pkg
                      , fr_mods_hidden = mod_hiddens, fr_pkgs_hidden = pkg_hiddens
@@ -652,6 +652,18 @@ cantFindErr cannot_find _ dflags mod_name find_result
               ptext (sLit "to the build-depends in your .cabal file.")
      | otherwise = Outputable.empty
 
+    looks_like_srcpkgid :: PackageKey -> SDoc
+    looks_like_srcpkgid pk
+     -- Unsafely coerce a package key FastString into a source package ID
+     -- FastString and see if it means anything.
+     | (pkg:pkgs) <- searchPackageId dflags (SourcePackageId (packageKeyFS pk))
+     = parens (text "This package key looks like the source package ID;" $$
+       text "the real package key is" <+> quotes (ftext (packageKeyFS (packageKey pkg))) $$
+       (if null pkgs then Outputable.empty
+        else text "and" <+> int (length pkgs) <+> text "other candidates"))
+     -- Todo: also check if it looks like a package name!
+     | otherwise = Outputable.empty
+
     mod_hidden pkg =
         ptext (sLit "it is a hidden module in the package") <+> quotes (ppr pkg)
 
diff --git a/testsuite/tests/th/T10279.hs b/testsuite/tests/th/T10279.hs
new file mode 100644
index 0000000..fbc2dbb
--- /dev/null
+++ b/testsuite/tests/th/T10279.hs
@@ -0,0 +1,10 @@
+module T10279 where
+import Language.Haskell.TH
+import Language.Haskell.TH.Syntax
+
+-- NB: rts-1.0 is used here because it doesn't change.
+-- You do need to pick the right version number, otherwise the
+-- error message doesn't recognize it as a source package ID,
+-- (This is OK,  since it will look obviously wrong when they
+-- try to find the package in their package database.)
+blah = $(conE (Name (mkOccName "Foo") (NameG VarName (mkPkgName "rts-1.0") (mkModName "A"))))
diff --git a/testsuite/tests/th/T10279.stderr b/testsuite/tests/th/T10279.stderr
new file mode 100644
index 0000000..9c72bf9
--- /dev/null
+++ b/testsuite/tests/th/T10279.stderr
@@ -0,0 +1,8 @@
+
+T10279.hs:10:10:
+    Failed to load interface for ‘A’
+    no package key matching ‘rts-1.0’ was found
+    (This package key looks like the source package ID;
+     the real package key is ‘rts’)
+    In the expression: (rts-1.0:A.Foo)
+    In an equation for ‘blah’: blah = (rts-1.0:A.Foo)
diff --git a/testsuite/tests/th/all.T b/testsuite/tests/th/all.T
index 335363b..bc6ca5d 100644
--- a/testsuite/tests/th/all.T
+++ b/testsuite/tests/th/all.T
@@ -359,3 +359,4 @@ test('T8031', normal, compile, ['-v0'])
 test('T8624', normal, run_command, ['$MAKE -s --no-print-directory T8624'])
 test('TH_Lift', normal, compile, ['-v0'])
 test('T10019', normal, ghci_script, ['T10019.script'])
+test('T10279', normal, compile_fail, ['-v0'])



More information about the ghc-commits mailing list