Skip to content

Commit 54267fb

Browse files
authored
[spec] Move enum to base type conversion example to enum.dd (#3684)
Follow up to #3683.
1 parent e27e761 commit 54267fb

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

spec/enum.dd

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,24 @@ $(H2 $(LNAME2 named_enums, Named Enums))
7575
*AssignExpression*. Otherwise, it defaults to
7676
type $(CODE int).)
7777

78-
* A named enum member can be
79-
$(DDSUBLINK spec/type, implicit-conversions, implicitly cast to its $(I EnumBaseType)).
78+
* A named enum member can be implicitly cast to its $(I EnumBaseType).
8079
* An $(I EnumBaseType) instance cannot be implicitly cast to a named enum type.
81-
* A named enum member does not have an individual $(I Type).
80+
81+
$(SPEC_RUNNABLE_EXAMPLE_FAIL
82+
-------------------
83+
int i;
84+
85+
enum Foo { E }
86+
Foo f;
87+
i = f; // OK
88+
f = i; // error
89+
f = cast(Foo)i; // OK
90+
f = 0; // error
91+
f = Foo.E; // OK
92+
-------------------
93+
)
94+
95+
$(P A named enum member does not have an individual $(I Type).)
8296

8397
$(P The value of an $(GLINK EnumMember) is given by its *AssignExpression* if present.
8498
If there is no *AssignExpression* and it is the first $(I EnumMember),

spec/type.dd

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -226,23 +226,9 @@ $(H3 $(LEGACY_LNAME2 Implicit Conversions, implicit-conversions, Implicit Conver
226226
types as required. The rules for integers are detailed in the next sections.
227227
)
228228

229-
$(P An enum can be implicitly converted to its base
229+
$(P An enum can be $(DDSUBLINK spec/enum, named_enums, implicitly converted) to its base
230230
type, but going the other way requires an explicit
231-
conversion. For example:)
232-
233-
$(SPEC_RUNNABLE_EXAMPLE_FAIL
234-
-------------------
235-
int i;
236-
237-
enum Foo { E }
238-
Foo f;
239-
i = f; // OK
240-
f = i; // error
241-
f = cast(Foo)i; // OK
242-
f = 0; // error
243-
f = Foo.E; // OK
244-
-------------------
245-
)
231+
conversion.)
246232

247233
$(UL
248234
$(LI All types implicitly convert to $(RELATIVE_LINK2 noreturn, `noreturn`).)

0 commit comments

Comments
 (0)