Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,866
    • Issues 4,866
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 455
    • Merge requests 455
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #17551
Closed
Open
Created 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.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking