Skip to content

Commit 48b7656

Browse files
committed
Update reference with currently implemented rules
1 parent 16b1421 commit 48b7656

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

docs/docs/reference/enums/desugarEnums.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ map into case classes or vals.
136136
where `n` is the ordinal number of the case in the companion object,
137137
starting from 0.
138138

139-
140139
### Equality
141140

142141
An `enum` type contains a `scala.Eq` instance that restricts values of the `enum` type to
@@ -171,3 +170,20 @@ Companion objects that contain at least one simple case define in addition:
171170
def toString = name
172171
$values.register(this) // register enum value so that `valueOf` and `values` can return it.
173172
}
173+
174+
### Scopes for Enum Cases
175+
176+
A case in an `enum` is treated similarly to a secondary constructor. It cannot access
177+
with simple identifiers value parameters or instance members of the enclosing `enum`.
178+
179+
Even though translated enum cases are located in the enum's companion object, they
180+
cannot access with simple identifiers any members defined locally in the enclosing
181+
object either. The compiler is free to typecheck enum cases in the scope of the
182+
enclosing companion object but it must then flag any illegal accesses to the object's
183+
members.
184+
185+
### Other Rules
186+
187+
A normal case class which is not produced from an enum case is not allowed to extend
188+
`scala.Enum`. This ensures that the only cases of an anum are the ones that are
189+
explictly declared in it.

0 commit comments

Comments
 (0)