Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • 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,836
    • Issues 4,836
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 457
    • Merge requests 457
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
    • Value stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #18776

Closed
Open
Created Sep 30, 2020 by Adam Gundry@adamgundryDeveloper

Improve "No instance for HasField" error messages

The built-in HasField x r a constraint is solved automatically whenever x is a field label that belongs to the type r (except if the field is not in scope, or for a few other corner cases, e.g. the field type is existential, higher-rank or unboxed). If it is not solved automatically, however, the error message is typically just

No instance for (HasField "foo" T ()) arising from ...

which is rather uninformative. It would be better to customise the error reporting:

  • If the type r is not a record type at all, we could mention that fact.
  • If the type r is a record type, but does not have the named field, we could suggest similarly-named fields (like how the renamer suggests possibilities for not-in-scope identifiers).
  • If the field does belong to the type, but is not in scope, we could say that and suggest importing it.
  • If the field type is existential, higher-rank or unboxed, we could explain that such fields cannot be used with HasField.
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking