Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
GHC
GHC
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,322
    • Issues 4,322
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 362
    • Merge Requests 362
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Security & Compliance
    • Security & Compliance
    • Dependency List
    • License Compliance
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #14032

Closed
Open
Opened Jul 26, 2017 by Ryan Scott@RyanGlScottMaintainer

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
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#14032