[commit: ghc] master: Warn if you explicitly export an identifier with warning attached. (0bbcf76)

git at git.haskell.org git at git.haskell.org
Wed Jan 11 14:54:27 UTC 2017


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

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

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

commit 0bbcf76a349ed2c1d03907f2f74e5436859d59b0
Author: Edward Z. Yang <ezyang at cs.stanford.edu>
Date:   Thu Dec 29 21:39:27 2016 -0800

    Warn if you explicitly export an identifier with warning attached.
    
    Summary:
    This won't stop people from attempting to use this identifier
    (since it is still always going to be in the export list), but
    having an explicit reference to something people shouldn't
    use is a smell, so warn about it.
    
    Signed-off-by: Edward Z. Yang <ezyang at cs.stanford.edu>
    
    Test Plan: validate
    
    Reviewers: simonpj, austin, bgamari
    
    Subscribers: thomie
    
    Differential Revision: https://phabricator.haskell.org/D2907


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

0bbcf76a349ed2c1d03907f2f74e5436859d59b0
 compiler/typecheck/TcBackpack.hs                      | 15 ++++++++++++++-
 testsuite/tests/backpack/should_fail/bkpfail35.stderr |  4 ++++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/compiler/typecheck/TcBackpack.hs b/compiler/typecheck/TcBackpack.hs
index 9cc2997..76cb88d 100644
--- a/compiler/typecheck/TcBackpack.hs
+++ b/compiler/typecheck/TcBackpack.hs
@@ -459,9 +459,22 @@ mergeSignatures hsmod lcl_iface0 = do
     tcg_env <- getGblEnv
 
     -- Make sure we didn't refer to anything that doesn't actually exist
-    _ <- exports_from_avail mb_exports rdr_env
+    (mb_lies, _) <- exports_from_avail mb_exports rdr_env
                         (tcg_imports tcg_env) (tcg_semantic_mod tcg_env)
 
+    -- If you tried to explicitly export an identifier that has a warning
+    -- attached to it, that's probably a mistake.  Warn about it.
+    case mb_lies of
+      Nothing -> return ()
+      Just lies ->
+        forM_ (concatMap (\(L loc x) -> map (L loc) (ieNames x)) lies) $ \(L loc n) ->
+          setSrcSpan loc $
+            unless (nameOccName n `elemOccSet` ok_to_use) $
+                addWarn NoReason $ vcat [
+                    text "Exported identifier" <+> quotes (ppr n) <+> text "will cause warnings if used.",
+                    parens (text "To suppress this warning, remove" <+> quotes (ppr n) <+> text "from the export list of this signature.")
+                    ]
+
     failIfErrsM
 
     -- STEP 4: Rename the interfaces
diff --git a/testsuite/tests/backpack/should_fail/bkpfail35.stderr b/testsuite/tests/backpack/should_fail/bkpfail35.stderr
index f90d0e2..e371488 100644
--- a/testsuite/tests/backpack/should_fail/bkpfail35.stderr
+++ b/testsuite/tests/backpack/should_fail/bkpfail35.stderr
@@ -3,6 +3,10 @@
   [2 of 2] Compiling B                ( p/B.hs, nothing )
 [2 of 4] Processing q
   [1 of 1] Compiling A[sig]           ( q/A.hsig, nothing )
+
+bkpfail35.bkp:8:18: warning:
+    Exported identifier ‘x’ will cause warnings if used.
+    (To suppress this warning, remove ‘x’ from the export list of this signature.)
 [3 of 4] Processing aimpl
   Instantiating aimpl
   [1 of 1] Compiling A                ( aimpl/A.hs, bkpfail35.out/aimpl/A.o )



More information about the ghc-commits mailing list