Skip to content

Commit e47f8bf

Browse files
authored
[spec/enum] Tweak named enum docs (#3923)
Move enum variables up as they were already used in the implicit conversion example, and remove subheading (keeping anchor). Move link to `final switch` up too. Add *Enum Member Values* subheading.
1 parent e49e6c7 commit e47f8bf

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

spec/enum.dd

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,25 @@ $(H2 $(LNAME2 named_enums, Named Enums))
6969
enum X { A, B, C } // named enum
7070
---
7171

72+
$(LEGACY_LNAME2 enum_default_initializer, enum_variables)
73+
74+
$(P A variable can be of named enum type.
75+
Its default initializer is the first member defined for the enum type.
76+
)
77+
78+
$(SPEC_RUNNABLE_EXAMPLE_RUN
79+
------
80+
enum X { A = 3, B, C }
81+
82+
X x;
83+
assert(x == X.A);
84+
x |= X.B;
85+
assert(x & X.A);
86+
------
87+
)
88+
89+
$(P The result type of a binary operation on a named enum is defined
90+
$(DDSUBLINK spec/type, enum-ops, here).)
7291

7392
$(P If the $(GLINK EnumBaseType) is not explicitly set, and the first
7493
$(I EnumMember) has an *AssignExpression*, it is set to the type of that
@@ -80,10 +99,10 @@ $(H2 $(LNAME2 named_enums, Named Enums))
8099

81100
$(SPEC_RUNNABLE_EXAMPLE_FAIL
82101
-------------------
83-
int i;
84-
85102
enum Foo { E }
103+
86104
Foo f;
105+
int i;
87106
i = f; // OK
88107
f = i; // error
89108
f = cast(Foo)i; // OK
@@ -92,7 +111,11 @@ f = Foo.E; // OK
92111
-------------------
93112
)
94113

95-
$(P A named enum member does not have an individual $(I Type).)
114+
$(P A named enum member cannot declare its own $(I Type).)
115+
116+
$(P See also: $(DDSUBLINK spec/statement, final-switch-statement, `final switch`) on a named enum.)
117+
118+
$(H3 $(LNAME2 member_values, Enum Member Values))
96119

97120
$(P The value of an $(GLINK EnumMember) is given by its *AssignExpression* if present.
98121
If there is no *AssignExpression* and it is the first $(I EnumMember),
@@ -153,27 +176,6 @@ enum E : C
153176
writeln(X.init); // error: enum X is opaque and has no default initializer
154177
---
155178

156-
$(H3 $(LEGACY_LNAME2 enum_default_initializer, enum_variables, Enum Variables))
157-
158-
$(P A variable can be of named enum type.
159-
The default initializer is the first member defined for the enum type.
160-
)
161-
162-
$(SPEC_RUNNABLE_EXAMPLE_RUN
163-
------
164-
enum X { A = 3, B, C }
165-
X x;
166-
assert(x == X.A);
167-
x |= X.B;
168-
assert(x & X.A);
169-
------
170-
)
171-
172-
$(P The result type of a binary operation performed when the operands have
173-
different types is defined $(DDSUBLINK spec/type, enum-ops, here).)
174-
175-
$(P See also: $(DDSUBLINK spec/statement, final-switch-statement, `final switch`).)
176-
177179
$(H3 $(LNAME2 enum_properties, Enum Properties))
178180

179181
$(P Enum properties only exist for named enums.

0 commit comments

Comments
 (0)