Skip to content

Commit 361a754

Browse files
authored
Document HiddenConstructors (documentationjs#354)
* Document `HiddenConstructors`
1 parent 20bcfc2 commit 361a754

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

errors/HiddenConstructors.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# `HiddenConstructors` Warning
2+
3+
## Example
4+
5+
```purescript
6+
module ShortFailingExample (N) where
7+
8+
import Data.Newtype (class Newtype)
9+
import Data.Generic.Rep (class Generic)
10+
11+
newtype N a = MkN a
12+
13+
derive instance newtypeN :: Newtype (N a) _
14+
derive instance genericN :: Generic (N a) _
15+
```
16+
17+
## Cause
18+
19+
Instances of `Newtype` and `Generic` allow to match values of their type with `unwrap` and `from`, and to construct them with `wrap` or `to` hence making the constructors public.
20+
21+
## Fix
22+
23+
- Export the constructors:
24+
25+
```diff
26+
-module ShortFailingExample (N) where
27+
+module ShortFailingExample (N(..)) where
28+
```
29+
30+
- or remove the instances:
31+
32+
```diff
33+
module ShortFailingExample (N) where
34+
35+
-import Data.Newtype (class Newtype)
36+
-import Data.Generic.Rep (class Generic)
37+
38+
newtype N a = MkN a
39+
40+
-derive instance newtypeN :: Newtype (N a) _
41+
-derive instance genericN :: Generic (N a) _
42+
```

0 commit comments

Comments
 (0)