Skip to content

Commit a33d11e

Browse files
committed
Explain GHC-39999 arising from OverloadedRecordDot
1 parent 0b11d41 commit a33d11e

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Main where
2+
3+
import DataType (MyData(foo))
4+
5+
getFoo :: MyData -> Int
6+
getFoo x = x.foo
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Main where
2+
3+
import DataType (MyData)
4+
5+
getFoo :: MyData -> Int
6+
getFoo x = x.foo
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
title: A usage of `x.foo` with the field `foo` not being in scape
3+
---
4+
5+
## Error message
6+
7+
```
8+
src/Main.hs:6:12: error: [GHC-39999]
9+
• No instance for ‘GHC.Records.HasField "foo" MyData Int’
10+
arising from selecting the field ‘foo’
11+
Perhaps you want to add ‘foo’ to the import list in the import of
12+
‘DataType’ (src/Main.hs:3:1-24).
13+
• In the expression: x.foo
14+
In an equation for ‘getFoo’: getFoo x = x.foo
15+
|
16+
6 | getFoo x = x.foo
17+
|
18+
```
19+
20+
## Explanation
21+
22+
This error arises when using the `OverloadedRecordDot` extension.
23+
Given a module exporting a record:
24+
25+
```haskell
26+
module DataType where
27+
28+
data MyData = MyData { foo :: Int, bar :: String }
29+
```
30+
31+
When `MyData` is imported into a module without also importing the fields, attempting to access fields using `OverloadedRecordDot` will result in an error.
32+
33+
Adding the field to the import list will resolve the issue.

0 commit comments

Comments
 (0)