Confusing OverloadedRecordDot error
Summary
OverloadedRecords throws confusing error when fields aren't imported:
No instance for (GHC.Records.HasField "bar" Foo Int)
Since instances should be imported with data implicitly, it's not really clear how to fix it
Steps to reproduce
Foo.hs
module Foo where
data Foo = Foo
{ bar :: Int
, baz :: String
}
Qux.hs
{-# LANGUAGE OverloadedRecordDot #-}
module Qux where
import Foo (Foo)
qux :: Foo -> Int
qux foo = foo.bar
Gives
• No instance for (GHC.Records.HasField "bar" Foo Int)
arising from selecting the field ‘bar’
• In the expression: foo.bar
In an equation for ‘qux’: qux foo = foo.bar
Qux.hs
{-# LANGUAGE OverloadedRecordDot #-}
module Qux where
import Foo (Foo(..)) -- it's the fix, but it's very unobvious
qux :: Foo -> Int
qux foo = foo.bar
Expected behavior
It should have right error message and it shouldn't mention any instance
because it breaks reasoning about GHC
Environment
- GHC version used: 9.2.5