[commit: ghc] master: Emit error in case of duplicate GRE; fixes #7241 (c226d25)

git at git.haskell.org git at git.haskell.org
Thu Jun 5 14:12:07 UTC 2014


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

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

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

commit c226d25fef519db663d0c9efe7845637423f1dca
Author: Yuras Shumovich <shumovichy at gmail.com>
Date:   Thu Jun 5 07:56:05 2014 -0500

    Emit error in case of duplicate GRE; fixes #7241
    
    Signed-off-by: Austin Seipp <austin at well-typed.com>


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

c226d25fef519db663d0c9efe7845637423f1dca
 compiler/rename/RnEnv.lhs       | 21 ++++++++++++++-------
 testsuite/tests/th/T7241.hs     |  7 +++++++
 testsuite/tests/th/T7241.stderr |  6 ++++++
 testsuite/tests/th/T8932.stderr |  6 ++++++
 testsuite/tests/th/all.T        |  1 +
 5 files changed, 34 insertions(+), 7 deletions(-)

diff --git a/compiler/rename/RnEnv.lhs b/compiler/rename/RnEnv.lhs
index bdc2cdf..a89ab1f 100644
--- a/compiler/rename/RnEnv.lhs
+++ b/compiler/rename/RnEnv.lhs
@@ -268,22 +268,29 @@ lookupExactOcc name
                        ; return name
                        }
 
-           (gre:_) -> return (gre_name gre) }
+           [gre]   -> return (gre_name gre)
+           (gre:_) -> do {addErr dup_nm_err
+                         ; return (gre_name gre)
+                         }
            -- We can get more than one GRE here, if there are multiple 
-           -- bindings for the same name; but there will already be a 
-           -- reported error for the duplicate.  (If we add the error 
-           -- rather than stopping when we encounter it.) 
-           -- So all we need do here is not crash.  
-           -- Example is Trac #8932:
+           -- bindings for the same name. Sometimes they are catched later
+           -- by findLocalDupsRdrEnv, like in the this example (Trac #8932):
            --    $( [d| foo :: a->a; foo x = x |])
            --    foo = True
-           -- Here the 'foo' in the splice turns into an Exact Name
+           -- But when the names are totally identical, we get panic (Trac #7241):
+           --    $(newName "Foo" >>= \o -> return [DataD [] o [] [RecC o []] [''Show]])
+           -- So, lets emit error here, even if it will lead to two errors in some cases.
+       }
 
   where
     exact_nm_err = hang (ptext (sLit "The exact Name") <+> quotes (ppr name) <+> ptext (sLit "is not in scope"))
                       2 (vcat [ ptext (sLit "Probable cause: you used a unique Template Haskell name (NameU), ")
                               , ptext (sLit "perhaps via newName, but did not bind it")
                               , ptext (sLit "If that's it, then -ddump-splices might be useful") ])
+    dup_nm_err   = hang (ptext (sLit "Duplicate exact Name") <+> quotes (ppr $ nameOccName name))
+                      2 (vcat [ ptext (sLit "Probable cause: you used a unique Template Haskell name (NameU), ")
+                              , ptext (sLit "perhaps via newName, but bound it multiple times")
+                              , ptext (sLit "If that's it, then -ddump-splices might be useful") ])
 
 -----------------------------------------------
 lookupInstDeclBndr :: Name -> SDoc -> RdrName -> RnM Name
diff --git a/testsuite/tests/th/T7241.hs b/testsuite/tests/th/T7241.hs
new file mode 100644
index 0000000..971a267
--- /dev/null
+++ b/testsuite/tests/th/T7241.hs
@@ -0,0 +1,7 @@
+{-# LANGUAGE TemplateHaskell #-}
+
+module T7241 where
+
+import Language.Haskell.TH
+
+$(newName "Foo" >>= \o -> return [DataD [] o [] [RecC o []] []])
diff --git a/testsuite/tests/th/T7241.stderr b/testsuite/tests/th/T7241.stderr
new file mode 100644
index 0000000..343cdc8
--- /dev/null
+++ b/testsuite/tests/th/T7241.stderr
@@ -0,0 +1,6 @@
+
+T7241.hs:7:3:
+    Duplicate exact Name ‘Foo’
+      Probable cause: you used a unique Template Haskell name (NameU), 
+      perhaps via newName, but bound it multiple times
+      If that's it, then -ddump-splices might be useful
diff --git a/testsuite/tests/th/T8932.stderr b/testsuite/tests/th/T8932.stderr
index 0e0f977..c861235 100644
--- a/testsuite/tests/th/T8932.stderr
+++ b/testsuite/tests/th/T8932.stderr
@@ -1,4 +1,10 @@
 
+T8932.hs:5:3:
+    Duplicate exact Name ‘foo’
+      Probable cause: you used a unique Template Haskell name (NameU), 
+      perhaps via newName, but bound it multiple times
+      If that's it, then -ddump-splices might be useful
+
 T8932.hs:11:1:
     Multiple declarations of ‘foo’
     Declared at: T8932.hs:5:3
diff --git a/testsuite/tests/th/all.T b/testsuite/tests/th/all.T
index 22bb7cc..ca7ead6 100644
--- a/testsuite/tests/th/all.T
+++ b/testsuite/tests/th/all.T
@@ -326,4 +326,5 @@ test('T8884', normal, compile, ['-v0'])
 test('T8954', normal, compile, ['-v0'])
 test('T8932', normal, compile_fail, ['-v0'])
 test('T8987', normal, compile_fail, ['-v0'])
+test('T7241', normal, compile_fail, ['-v0'])
 



More information about the ghc-commits mailing list