Commit c226d25f authored by Yuras's avatar Yuras Committed by Austin Seipp

Emit error in case of duplicate GRE; fixes #7241

Signed-off-by: default avatarAustin Seipp <austin@well-typed.com>
parent 56ea745c
......@@ -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
......
{-# LANGUAGE TemplateHaskell #-}
module T7241 where
import Language.Haskell.TH
$(newName "Foo" >>= \o -> return [DataD [] o [] [RecC o []] []])
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
T8932.hs:11:1:
Multiple declarations of ‘foo’
Declared at: T8932.hs:5:3
T8932.hs:11:1
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
T8932.hs:11:1
......@@ -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'])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment