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
Copy file name to clipboardExpand all lines: docs/docs/reference/enums/desugarEnums.md
+26-7Lines changed: 26 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,9 +25,9 @@ some terminology and notational conventions:
25
25
26
26
The desugaring rules imply that class cases are mapped to case classes, and singleton cases are mapped to `val` definitions.
27
27
28
-
There are eight desugaring rules. Rule (1) desugar enum definitions. Rules
28
+
There are nine desugaring rules. Rule (1) desugar enum definitions. Rules
29
29
(2) and (3) desugar simple cases. Rules (4) to (6) define extends clauses for cases that
30
-
are missing them. Rules (7) and (8) define how such cases with extends clauses
30
+
are missing them. Rules (7) to (9) define how such cases with extends clauses
31
31
map into case classes or vals.
32
32
33
33
1. An `enum` definition
@@ -80,7 +80,7 @@ map into case classes or vals.
80
80
case C extends E[B1, ..., Bn]
81
81
82
82
where `Bi` is `Li` if `Vi = '+'` and `Ui` if `Vi = '-'`. This result is then further
83
-
rewritten with rule (7). Simple cases of enums with non-variant type
83
+
rewritten with rule (8). Simple cases of enums with non-variant type
84
84
parameters are not permitted.
85
85
86
86
5. A class case without an extends clause
@@ -91,7 +91,7 @@ map into case classes or vals.
91
91
92
92
case C <type-params> <value-params> extends E
93
93
94
-
This result is then further rewritten with rule (8).
94
+
This result is then further rewritten with rule (9).
95
95
96
96
6. If `E` is an enum with type parameters `Ts`, a class case with neither type parameters nor an extends clause
97
97
@@ -101,9 +101,20 @@ map into case classes or vals.
101
101
102
102
case C[Ts] <value-params> extends E[Ts]
103
103
104
-
This result is then further rewritten with rule (8). For class cases that have type parameters themselves, an extends clause needs to be given explicitly.
104
+
This result is then further rewritten with rule (9). For class cases that have type parameters themselves, an extends clause needs to be given explicitly.
105
105
106
-
7. A value case
106
+
7. If `E` is an enum with type parameters `Ts`, a class case without type parameters but with an extends clause
107
+
108
+
case C <value-params> extends <parents>
109
+
110
+
expands to
111
+
112
+
case C[Ts] <value-params> extends <parents>
113
+
114
+
provided at least one of the parameters `Ts` is mentioned in a parameter type in
115
+
`<value-params>` or in a type argument in `<parents>`.
116
+
117
+
8. A value case
107
118
108
119
case C extends <parents>
109
120
@@ -116,7 +127,10 @@ map into case classes or vals.
116
127
as one of the `enumValues` of the enumeration (see below). `$values` is a
117
128
compiler-defined private value in the companion object.
118
129
119
-
8. A class case
130
+
It is an error if a value case refers to a type parameter of the enclosing `enum`
131
+
in a type argument of `<parents>`.
132
+
133
+
9. A class case
120
134
121
135
case C <params> extends <parents>
122
136
@@ -134,6 +148,11 @@ map into case classes or vals.
134
148
where `n` is the ordinal number of the case in the companion object,
135
149
starting from 0.
136
150
151
+
It is an error if a value case refers to a type parameter of the enclosing `enum`
152
+
in a parameter type in `<params>` or in a type argument of `<parents>`, unless that parameter is already
153
+
a type parameter of the case, i.e. the parameter name is defined in `<params>`.
154
+
155
+
137
156
### Translation of Enumerations
138
157
139
158
Non-generic enums `E` that define one or more singleton cases
0 commit comments