You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
+
moduleDataTypewhere
27
+
28
+
dataMyData=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