Skip to content

Commit 680b688

Browse files
committed
Sol3
1 parent 5ff4c2c commit 680b688

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

compiler/src/dmd/enumsem.d

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,6 @@ void enumSemantic(Scope* sc, EnumDeclaration ed)
203203
deprecation(ed.loc, "`scope` as a type constraint is deprecated. Use `scope` at the usage site.");
204204
}
205205

206-
if (sc.inCfile)
207-
return cEnumSemantic(sc, ed);
208-
209-
// Setup scopes for each member but don't evaluate them yet
210-
// The actual enum member value computation will happen in semantic2
211206
Scope* sce;
212207
if (ed.isAnonymous())
213208
sce = sc;
@@ -219,7 +214,8 @@ void enumSemantic(Scope* sc, EnumDeclaration ed)
219214
sce = sce.startCTFE();
220215
sce.setNoFree(); // needed for getMaxMinValue()
221216

222-
// Each enum member gets the sce scope
217+
/* Each enum member gets the sce scope
218+
*/
223219
ed.members.foreachDsymbol( (s)
224220
{
225221
if (EnumMember em = s.isEnumMember())
@@ -232,9 +228,14 @@ void enumSemantic(Scope* sc, EnumDeclaration ed)
232228
*/
233229
addEnumMembersToSymtab(ed, sc, sc.getScopesym());
234230

235-
// For D enums, defer the member value computation to semantic2
236-
// to avoid circular reference issues with final switch statements
237-
ed.semanticRun = PASS.semantic;
231+
if (sc.inCfile)
232+
return cEnumSemantic(sc, ed);
233+
234+
ed.members.foreachDsymbol( (s)
235+
{
236+
if (EnumMember em = s.isEnumMember())
237+
em.dsymbolSemantic(em._scope);
238+
});
238239
//printf("ed.defaultval = %lld\n", ed.defaultval);
239240

240241
//if (ed.defaultval) printf("ed.defaultval: %s %s\n", ed.defaultval.toChars(), ed.defaultval.type.toChars());
@@ -541,7 +542,7 @@ void enumMemberSemantic(Scope* sc, EnumMember em)
541542
emax = emax.ctfeInterpret();
542543

543544
// check that (eprev != emax)
544-
Expression e = new EqualExp(EXP.equal, em.ed.loc, eprev, emax);
545+
Expression e = new EqualExp(EXP.equal, em.loc, eprev, emax);
545546
e = e.expressionSemantic(sc);
546547
e = e.ctfeInterpret();
547548
if (global.endGagging(errors))
@@ -552,6 +553,9 @@ void enumMemberSemantic(Scope* sc, EnumMember em)
552553
Expression e2 = DotIdExp.create(em.ed.loc, new TypeExp(em.ed.loc, tprev), Id.max);
553554
e2 = e2.expressionSemantic(sc);
554555
e2 = e2.ctfeInterpret();
556+
e2 = new EqualExp(EXP.equal, em.loc, eprev, e2);
557+
e2 = e2.expressionSemantic(sc);
558+
e2 = e2.ctfeInterpret();
555559
}
556560
// now any errors are for generating a value
557561
if (e.toInteger())

0 commit comments

Comments
 (0)