[GHC] #14032: Can't splice TH quote with infix declaration for name in two different namespaces
GHC
ghc-devs at haskell.org
Wed Jul 26 01:35:45 UTC 2017
#14032: Can't splice TH quote with infix declaration for name in two different
namespaces
-------------------------------------+-------------------------------------
Reporter: RyanGlScott | Owner: (none)
Type: bug | Status: new
Priority: normal | Milestone:
Component: Template | Version: 8.0.1
Haskell |
Keywords: | Operating System: Unknown/Multiple
Architecture: | Type of failure: None/Unknown
Unknown/Multiple |
Test Case: | Blocked By:
Blocking: | Related Tickets:
Differential Rev(s): | Wiki Page:
-------------------------------------+-------------------------------------
Spun off from #13799 (and
https://ghc.haskell.org/trac/ghc/ticket/13054#comment:2). This code
compiles:
{{{#!hs
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeOperators #-}
infix 5 :*:
data a :*: b = a :*: b
}}}
But this code does not:
{{{#!hs
{-# 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.)
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14032>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list