Skip to content

Commit f00102c

Browse files
committed
reword to avoid low level details
1 parent d26c089 commit f00102c

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

docs/_docs/reference/enums/enums.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ enum Planet(mass: Double, radius: Double):
7777
end Planet
7878
```
7979

80+
### User-defined companion object of enums
8081
It is also possible to define an explicit companion object for an enum:
8182

8283
```scala
@@ -89,13 +90,15 @@ object Planet:
8990
end Planet
9091
```
9192

92-
As explained [later](./desugarEnums.md), enum cases are expanded in the companion object of the enum.
93-
Even though the enum cases are written within the lexical scope of the enum template, they may not
94-
reference members of the enum class. Like secondary constructors, although written inside the template,
95-
they are scoped outside it.
93+
### Restrictions on Enum Cases
9694

97-
Similarly, they may not directly reference members of the companion object in which they expand.
98-
They are like default class arguments, which are also expanded in the class's companion. For example:
95+
Enum case declarations are similar to secondary constructors:
96+
they are scoped outside of the enum template, despite being declared within it.
97+
This means that enum case declarations cannot access inner members of the
98+
enum class.
99+
100+
Similarly, enum case declarations may not directly reference members of the enum's companion object,
101+
even if they are imported (directly, or by renaming). For example:
99102

100103
```scala
101104
import Planet.*
@@ -110,9 +113,9 @@ object Planet:
110113
private final val (EarthMass @ _, EarthRadius @ _) = (5.976e+24, 6.37814e6)
111114
end Planet
112115
```
113-
The fields for Mercury are not visible, and the fields for Venus may not be referenced directly.
114-
Since the direct reference after expansion shadows any import clause, the import statement does not make the fields available.
115-
Direct references using a renaming import are also disallowed.
116+
The fields referenced by `Mercury` are not visible, and the fields referenced by `Venus` may not
117+
be referenced directly (using `import Planet.*`). You must use an indirect reference,
118+
such as demonstrated with `Earth`.
116119

117120
### Deprecation of Enum Cases
118121

0 commit comments

Comments
 (0)