TemplateHaskell may block "Conflicting definitions" error to be checked
Summary
GHC accepts to compile the following definitions, but they look to contain "Conflicting definitions for 'x'" errors.
foo x $([p| x |] :: PatQ) = x -- x is the second argument
bar =
let {
x = "A"
; $([p| x |] :: PatQ) = "B"
} in x -- x is "B"
(This is pointed out by Kai-Oliver Prott at Haskell-cafe mailing list (archive))
Steps to reproduce
Compile the attached files with ghc
$ ls *.hs
Main.hs THPatTest.hs
$ ghc Main.hs
[1 of 2] Compiling THPatTest ( THPatTest.hs, THPatTest.o, THPatTest.dyn_o )
[2 of 2] Compiling Main ( Main.hs, Main.o, Main.dyn_o )
Linking Main ...
$ ./Main
(2,2,2)
(1,2,1)
Expected behavior
Each of foo
, bar
, and baz
defined in THPatTest.hs
should be reported as compilation error.
Each of foo'
, bar'
, and baz'
defined in THPatTest.hs
should be reported as compilation error at the point
they are spliced in Main.hs
(Let me excuse myself for being not sure about this is the desirable behavior, since it makes an existing code relying on the current behavior fail to compile.)
Environment
- GHC version used: 8.10.4, 9.0.1