haskell / haskell/error-messages

Selecting a nonexistent field using record dot yields error about missing HasField instance

Open
#539 5 comments 5 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
76
Forks
19
PR merge metrics
No merged PRs in 30d

Description

Using GHC 9.4.4:
```
λ> :set -XOverloadedRecordDot
λ> data Person = Person { name :: String, age :: Int } deriving (Eq, Show, Ord)
λ> john = Person "John" 34
λ> john.address

:4:1: error:
• No instance for (GHC.Records.HasField "address" Person a0)
arising from selecting the field ‘address’
• In the expression: john.address
In an equation for ‘it’: it = john.address
```

While this is technically a "correct" error message I believe we can do better. For example

```
:4:1: error:
• Cannot select nonexistent field ‘address’
from a record of type ‘Person’
• In the expression: john.address
In an equation for ‘it’: it = john.address
```
Whether to mention `HasField` at all is perhaps a question, but I believe that if a user is advanced enough to potentially want to mess with `HasField` then they don't need the error message to spell that out for them.

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the diagnostic with GHC 9.4.4 using OverloadedRecordDot and the Person example in the issue. Trace the error reporting for selecting john.address and update it so a nonexistent field reports that address cannot be selected from Person, then verify the revised diagnostic.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.