Confusing HasField error messages
Consider a simple record type and a module using it using OverloadedRecordDot:
module Record where
data R = R { f :: Int }
module UseRecord where
import Record (R)
f :: R -> Int
f r = r.f
The UseRecord module will fail to compile it does not not import the children of R. However, the error message produced by GHC 9.12 does not clearly suggest the cause:
src/UseRecord.hs:6:7: error: [GHC-39999]
• No instance for ‘ghc-internal-9.1202.0:GHC.Internal.Records.HasField
"f" R Int’
arising from selecting the field ‘f’
• In the expression: r.f
In an equation for ‘f’: f r = r.f
|
6 | f r = r.f
| ^^^
This should be addressed.
Originally described in https://github.com/martijnbastiaan/confusing-hasfield-errors.