Skip to content

Commit 6050f8a

Browse files
tbidneBinderDavid
authored andcommitted
Document GHC-61689
1 parent 41e1b74 commit 6050f8a

File tree

11 files changed

+95
-0
lines changed

11 files changed

+95
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module A (one) where
2+
3+
one :: ()
4+
one = ()
5+
6+
two :: ()
7+
two = ()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module SymbolNotExported where
2+
3+
import A (one)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module A (one) where
2+
3+
one :: ()
4+
one = ()
5+
6+
two :: ()
7+
two = ()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module SymbolNotExported where
2+
3+
import A (one, two)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
title: Importing an unexported symbol.
3+
---
4+
5+
## Message
6+
```
7+
SymbolNotExported.hs:3:16: error: [GHC-61689]
8+
Module ‘A’ does not export ‘two’.
9+
|
10+
3 | import A (one, two)
11+
| ^^^
12+
```
13+
14+
## Explanation
15+
16+
The module `SymbolNotExported` imports the symbol `two` even though `A` does not export it.
17+
18+
The fix is to remove the bad import.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{-# LANGUAGE NoFieldSelectors #-}
2+
3+
module A (Foo (..)) where
4+
5+
data Foo = MkFoo { fint :: Int, fchar :: Char }
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module NoFieldSelectors where
2+
3+
import A (Foo (MkFoo, fint))
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{-# LANGUAGE NoFieldSelectors #-}
2+
3+
module A (Foo (..)) where
4+
5+
data Foo = MkFoo { fint :: Int, fchar :: Char }
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module NoFieldSelectors where
2+
3+
import A (Foo (MkFoo), fint)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
title: Importing a field selector that has been disabled with NoFieldSelectors.
3+
---
4+
5+
## Message
6+
```
7+
NoFieldSelectors.hs:3:24: error: [GHC-61689]
8+
Module ‘A’ does not export ‘fint’.
9+
Suggested fix:
10+
Notice that ‘fint’ is a field selector belonging to the type ‘A.Foo’
11+
that has been suppressed by NoFieldSelectors.
12+
|
13+
3 | import A (Foo (MkFoo), fint)
14+
| ^^^^
15+
```
16+
17+
## Explanation
18+
19+
With `FieldSelectors` (the default), field selectors are exported such that the following two imports are equivalent:
20+
21+
```haskell
22+
23+
import A (Foo (MkFoo, fint))
24+
import A (Foo (MkFoo), fint)
25+
```
26+
27+
With `NoFieldSelectors` at the _definition site_ (`A.hs`), the second example is always an error:
28+
29+
```haskell
30+
import A (Foo (MkFoo), fint)
31+
```
32+
33+
The fix is to move the selector import to the type or remove it altogether.

0 commit comments

Comments
 (0)