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
  • #21444
Closed
Open
Created Apr 27, 2022 by Richard Eisenberg@raeDeveloper

Ambiguous record update error message text

Suppose we have

data S = MkS { foo, bar, baz :: Int }
data T = MkT { foo, bar, baz :: Int }

blah x = x { foo = 1, bar = 2, baz = 3 }

GHC rightly errors, with

Scratch.hs:35:10: error:
    * Record update is ambiguous, and requires a type signature
    * In the expression: x {foo = 1, bar = 2, baz = 3}
      In an equation for `blah': blah x = x {foo = 1, bar = 2, baz = 3}
   |
35 | blah x = x { foo = 1, bar = 2, baz = 3 }
   |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

But, with the reduction in power of -XDuplicateRecordFields coming soon, a type signature will be insufficient for disambiguating. Indeed, there is no good way to disambiguate this record update; the user will have to rewrite their code, likely to use a manual case or something like it. (If the records were in different modules, module prefixes could also help.)

In https://github.com/haskell/error-messages/issues/57, @adamgundry and I came up with

Scratch.hs:35:10: error:
    • Record update for fields 'foo', 'bar' and 'baz' is ambiguous,
      because they all appear in types 'S' and 'T'.
    * In the expression: x {foo = 1, bar = 2, baz = 3}
      In an equation for `blah': blah x = x {foo = 1, bar = 2, baz = 3}
   |
35 | blah x = x { foo = 1, bar = 2, baz = 3 }
   |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

That would seem to be a nice little improvement, giving the user more information and not suggesting an ineffective fix.

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