Skip to content

Commit 8013ea4

Browse files
committed
Fixup markup in union-types
1 parent 8d750a1 commit 8013ea4

File tree

2 files changed

+65
-46
lines changed

2 files changed

+65
-46
lines changed

docs/docs/reference/desugarEnums.md

Lines changed: 63 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -41,106 +41,125 @@ comma separated simple cases into a sequence of cases.
4141

4242
2. An enum class definition
4343

44-
enum class E ... extends <parents> ...
44+
enum class E ... extends <parents> ...
4545

4646
expands to a `sealed` `abstract` class that extends the `scala.Enum` trait:
4747

4848
sealed abstract class E ... extends <parents> with scala.Enum ...
4949

5050
3. If `E` is an enum class without type parameters, then a case in its companion object without an extends clause
5151

52-
case C <params> <body>
52+
case C <params> <body>
5353

5454
expands to
5555

56-
case C <params> <body> extends E
56+
case C <params> <body> extends E
5757

58-
4. If `E` is an enum class with type parameters `Ts`, then a case in its companion object without an extends clause
58+
4. If `E` is an enum class with type parameters `Ts`, then a case in its
59+
companion object without an extends clause
5960

60-
case C <params> <body>
61+
case C <params> <body>
6162

62-
expands according to two alternatives, depending whether `C` has type parameters or not. If `C` has type parameters, they must have the same names and appear in the same order as the enum type parameters `Ts` (variances may be different, however). In this case
63+
expands according to two alternatives, depending whether `C` has type
64+
parameters or not. If `C` has type parameters, they must have the same
65+
names and appear in the same order as the enum type parameters `Ts`
66+
(variances may be different, however). In this case
6367

64-
case C [Ts] <params> <body>
68+
case C [Ts] <params> <body>
6569

66-
expands to
70+
expands to
6771

68-
case C[Ts] <params> extends E[Ts] <body>
72+
case C[Ts] <params> extends E[Ts] <body>
6973

70-
For the case where `C` does not have type parameters, assume `E`'s type parameters are
74+
For the case where `C` does not have type parameters, assume `E`'s type
75+
parameters are
7176

72-
V1 T1 > L1 <: U1 , ... , Vn Tn >: Ln <: Un (n > 0)
77+
V1 T1 > L1 <: U1 , ... , Vn Tn >: Ln <: Un (n > 0)
7378

74-
where each of the variances `Vi` is either `'+'` or `'-'`. Then the case expands to
79+
where each of the variances `Vi` is either `'+'` or `'-'`. Then the case
80+
expands to
7581

76-
case C <params> extends E[B1, ..., Bn] <body>
82+
case C <params> extends E[B1, ..., Bn] <body>
7783

78-
where `Bi` is `Li` if `Vi = '+'` and `Ui` if `Vi = '-'`. It is an error if `Bi` refers to some other type parameter `Tj (j = 0,..,n-1)`. It is also an error if `E` has type parameters that are non-variant.
84+
where `Bi` is `Li` if `Vi = '+'` and `Ui` if `Vi = '-'`. It is an error if
85+
`Bi` refers to some other type parameter `Tj (j = 0,..,n-1)`. It is also
86+
an error if `E` has type parameters that are non-variant.
7987

8088
5. A class case
8189

82-
case C <params> ...
90+
case C <params> ...
8391

84-
expands analogous to a case class:
92+
expands analogous to a case class:
8593

86-
final case class C <params> ...
94+
final case class C <params> ...
8795

88-
However, unlike for a regular case class, the return type of the associated `apply` method is a fully parameterized type instance of the enum class `E` itself instead of `C`. Also the enum case defines an `enumTag` method of the form
96+
However, unlike for a regular case class, the return type of the associated
97+
`apply` method is a fully parameterized type instance of the enum class `E`
98+
itself instead of `C`. Also the enum case defines an `enumTag` method of
99+
the form
89100

90-
def enumTag = n
101+
def enumTag = n
91102

92-
where `n` is the ordinal number of the case in the companion object, starting from 0.
103+
where `n` is the ordinal number of the case in the companion object,
104+
starting from 0.
93105

94106
6. A value case
95107

96-
case C extends <parents> <body>
108+
case C extends <parents> <body>
97109

98-
expands to a value definition
110+
expands to a value definition
99111

100-
val C = new <parents> { <body>; def enumTag = n; $values.register(this) }
112+
val C = new <parents> { <body>; def enumTag = n; $values.register(this) }
101113

102-
where `n` is the ordinal number of the case in the companion object, starting from 0.
103-
The statement `$values.register(this)` registers the value as one of the `enumValues` of the
104-
enumeration (see below). `$values` is a compiler-defined private value in
105-
the companion object.
114+
where `n` is the ordinal number of the case in the companion object,
115+
starting from 0. The statement `$values.register(this)` registers the value
116+
as one of the `enumValues` of the enumeration (see below). `$values` is a
117+
compiler-defined private value in the companion object.
106118

107119
7. A simple case
108120

109-
case C
121+
case C
110122

111-
of an enum class `E` that does not take type parameters expands to
123+
of an enum class `E` that does not take type parameters expands to
112124

113-
val C = $new(n, "C")
125+
val C = $new(n, "C")
114126

115-
Here, `$new` is a private method that creates an instance of of `E` (see below).
127+
Here, `$new` is a private method that creates an instance of of `E` (see
128+
below).
116129

117130
8. A simple case consisting of a comma-separated list of enum names
118131

119132
case C_1, ..., C_n
120133

121-
expands to
134+
expands to
122135

123-
case C_1; ...; case C_n
136+
case C_1; ...; case C_n
124137

125-
Any modifiers or annotations on the original case extend to all expanded cases.
138+
Any modifiers or annotations on the original case extend to all expanded
139+
cases.
126140

127141
## Translation of Enumerations
128142

129143
Non-generic enum classes `E` that define one or more singleton cases
130144
are called _enumerations_. Companion objects of enumerations define
131145
the following additional members.
132146

133-
- A method `enumValue` of type `scala.collection.immutable.Map[Int, E]`. `enumValue(n)` returns the singleton case value with ordinal number `n`.
134-
- A method `enumValueNamed` of type `scala.collection.immutable.Map[String, E]`. `enumValueNamed(s)` returns the singleton case value whose `toString` representation is `s`.
135-
- A method `enumValues` which returns an `Iterable[E]` of all singleton case values in `E`, in the order of their definitions.
147+
- A method `enumValue` of type `scala.collection.immutable.Map[Int, E]`.
148+
`enumValue(n)` returns the singleton case value with ordinal number `n`.
149+
- A method `enumValueNamed` of type `scala.collection.immutable.Map[String, E]`.
150+
`enumValueNamed(s)` returns the singleton case value whose `toString`
151+
representation is `s`.
152+
- A method `enumValues` which returns an `Iterable[E]` of all singleton case
153+
values in `E`, in the order of their definitions.
136154

137155
Companion objects that contain at least one simple case define in addition:
138156

139-
- A private method `$new` which defines a new simple case value with given ordinal number and name. This method can be thought as being defined as follows.
140-
141-
def $new(tag: Int, name: String): ET = new E {
142-
def enumTag = tag
143-
def toString = name
144-
$values.register(this) // register enum value so that `valueOf` and `values` can return it.
145-
}
157+
- A private method `$new` which defines a new simple case value with given
158+
ordinal number and name. This method can be thought as being defined as
159+
follows.
146160

161+
def $new(tag: Int, name: String): ET = new E {
162+
def enumTag = tag
163+
def toString = name
164+
$values.register(this) // register enum value so that `valueOf` and `values` can return it.
165+
}

docs/docs/reference/union-types.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ val either: Password | UserName = UserName(Eve)
4343
```
4444

4545
The type of `res2` is `Object | Product`, which is a supertype of
46-
`UserName` and `Product, but not the least supertype `Password |
46+
`UserName` and `Product`, but not the least supertype `Password |
4747
UserName`. If we want the least supertype, we have to give it
4848
explicitely, as is done for the type of `Either`. More precisely, the
4949
typechecker will _widen_ a union type to a non-union type when
50-
inferring the type of ` `val` or `var`, or the result type of a `def`,
50+
inferring the type of `val` or `var`, or the result type of a `def`,
5151
or the argument to pass for a type parameter. The widened type of `A
5252
| B` is usually the intersection of all class or trait types that are
5353
supertypes of both `A` and `B`; it does not include any refinements.

0 commit comments

Comments
 (0)