Can't splice TH quote with infix declaration for name in two different namespaces
Spun off from #13799 (closed) (and #13054##14032). This code compiles:
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeOperators #-}
infix 5 :*:
data a :*: b = a :*: b
But this code does not:
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeOperators #-}
$([d| infix 5 :*:
data a :*: b = a :*: b
|])
$ /opt/ghc/8.2.1/bin/ghc -ddump-splices Bug.hs
[1 of 1] Compiling Main ( Bug.hs, Bug.o )
Bug.hs:(4,3)-(6,6): Splicing declarations
[d| infix 5 :*:_anM, :*:_anL
data a_anN :*:_anL b_anO = a_anN :*:_anM b_anO |]
======>
infix 5 :*:_a3IL
infix 5 :*:_a3IK
data (:*:_a3IK) a_a3IM b_a3IN = a_a3IM :*:_a3IL b_a3IN
Bug.hs:4:3: error:
Multiple fixity declarations for ‘:*:_a3IL’
also at Bug.hs:(4,3)-(6,6)
|
4 | $([d| infix 5 :*:
| ^^^^^^^^^^^^^^^...
Inspecting the -ddump-splices
output reveals why: when infix 5 :*:
is renamed, because :*:
refers to two different names in both the value and type namespaces, it actually gets renamed to infix 5 :*:_anM, :*:_anL
, where :*:_anM
and :*:_anL
are the same name with different uniques.
Normally, this isn't a problem, since feeding infix 5 :*:_anM, :*:_anL
to the typechecker works fine. However, when it's spliced in via Template Haskell, it gets fed back into the renamer, where it believes that :*:_anM
and :*:_anL
are duplicate names, causing the error.
Really, this is just a symptom of the fact that infix declarations are insufficiently powerful to encode information for identical names in different namespaces. But until GHC gains this ability, we need to find some workaround for this problem. My hunch is that we'll need to give GHC the power to recognize these sorts of duplicate fixity declarations in Convert
and only emit one actual fixity declaration per set of duplicates. (Disclaimer: I haven't worked out all the fiddly details yet.)
Trac metadata
Trac field | Value |
---|---|
Version | 8.0.1 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Template Haskell |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |