Skip to content

Commit 130fd60

Browse files
authored
Document roles and Coercible related errors (#352)
1 parent 6881582 commit 130fd60

File tree

6 files changed

+157
-0
lines changed

6 files changed

+157
-0
lines changed

errors/DuplicateRoleDeclaration.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# `DuplicateRoleDeclaration` Error
2+
3+
## Example
4+
5+
```purescript
6+
module ShortFailingExample where
7+
8+
data D a = D a
9+
type role D nominal
10+
type role D nominal
11+
```
12+
13+
## Cause
14+
15+
Multiple role declarations are provided for the same type.
16+
17+
## Fix
18+
19+
- Remove the extraneous role declarations:
20+
21+
```diff
22+
data D a = D a
23+
type role D nominal
24+
-type role D nominal
25+
```
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# `InvalidCoercibleInstanceDeclaration` Error
2+
3+
## Example
4+
5+
```purescript
6+
module ShortFailingExample where
7+
8+
import Prim.Coerce (class Coercible)
9+
10+
instance coercible :: Coercible a b
11+
```
12+
13+
## Cause
14+
15+
`Coercible` instances are solved by the compiler and cannot be declared.
16+
17+
## Fix
18+
19+
- Remove the instance declaration.

errors/OrphanRoleDeclaration.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# `OrphanRoleDeclaration` Error
2+
3+
## Example
4+
5+
```purescript
6+
module ShortFailingExample where
7+
8+
type role D nominal
9+
```
10+
11+
## Cause
12+
13+
A role declaration is provided but does not immediately follow it's declaration.
14+
15+
## Fix
16+
17+
- Check that you've provided the appropriate `data` or `newtype` declaration.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# `RoleDeclarationArityMismatch` Error
2+
3+
## Example
4+
5+
```purescript
6+
module ShortFailingExample where
7+
8+
data D a = D a
9+
type role D nominal nominal
10+
```
11+
12+
## Cause
13+
14+
The arity of a role declaration does not match the arity of its corresponding type.
15+
16+
## Fix
17+
18+
- Remove the extraneous roles:
19+
20+
```diff
21+
data D a = D a
22+
-type role D nominal nominal
23+
+type role D nominal
24+
```

errors/RoleMismatch.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# `RoleMismatch` Error
2+
3+
## Example
4+
5+
```purescript
6+
module ShortFailingExample where
7+
8+
data D a = D a
9+
type role D phantom
10+
```
11+
12+
```purescript
13+
module ShortFailingExample where
14+
15+
data D f a = D (f a)
16+
type role D representational representational
17+
```
18+
19+
## Cause
20+
21+
A parameter was assigned a role more permissive than required.
22+
23+
## Fix
24+
25+
- Remove or strengthen the role declaration:
26+
27+
```diff
28+
data D a = D a
29+
-type role D phantom
30+
+type role D representational
31+
```
32+
33+
```diff
34+
data D f a = D (f a)
35+
-type role D representational representational
36+
+type role D representational nominal
37+
```
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# `UnsupportedRoleDeclaration` Error
2+
3+
## Example
4+
5+
```purescript
6+
module ShortFailingExample where
7+
8+
class C a
9+
type role C representational
10+
```
11+
12+
```purescript
13+
module ShortFailingExample where
14+
15+
data D a = D a
16+
17+
type S a = D a
18+
type role S nominal
19+
```
20+
21+
## Cause
22+
23+
A role declaration is provided for a type synonym or a type class.
24+
25+
## Fix
26+
27+
- Remove the role declaration or provide a role declaration for the underlying type of the synonym instead:
28+
29+
```diff
30+
data D a = D a
31+
+type role D nominal
32+
33+
type S a = D a
34+
-type role S nominal
35+
```

0 commit comments

Comments
 (0)