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,246
    • Issues 4,246
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 397
    • Merge Requests 397
  • 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
  • #17551

Closed
Open
Opened Dec 08, 2019 by Maxim Koltsov@maksbotan

TemplateHaskell reify fails with fields from DuplicateRecordFields

Summary

Trying to reify fields from a record defined with DuplicateRecordFields extension leads to a confusing error message:

Exp.hs:11:1: error:
    Ambiguous occurrence ‘Exp.foo’
    It could refer to
       either the field ‘foo’, defined at Exp.hs:9:18
           or the field ‘foo’, defined at Exp.hs:8:18

Even if the name itself is not present in spliced code.

Steps to reproduce

Complete code snippet is here: https://gist.github.com/maksbotan/146b250ad295c0f5896a2313ce918cd0

Briefly:

  • Write TemplateHaskell function of type Name -> Q [Dec], where Name is supposed to refer to a data type.
  • reify the Name to get RecC info with Names of the
  • call reify on those Names to get their types
make :: Name -> Q [Dec]
make name = do
  TyConI (DataD _ _ _ _ [RecC con fields'] _) <- reify name
  let fields = [ field | (field, _, _) <- fields' ]
  fieldInfos <- mapM reify fields

  return []

When the record in question is defined in a file with DuplicateRecordFields and really has duplicate fields, GHC will emit a compilation error with confusing message.

Expected behavior

Since I reifyed concrete record type, I expect to be able to extras its fields without any ambiguity.

Environment

  • GHC version used: 8.6.3 (Stack LTS-13.6), 8.6.5 (nix), 8.8.1 (nix)
  • Operating System: macOS mojave

This looks related to #14848 and #17381, but in my case I don't do any quasiquoting. Another difference is that in my case the error message is really misleading.

Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#17551