module foo;
struct A { B b; }
enum B { Z }
$ dmd -c foo.d
foo.d(3): Error: enum B is forward referenced
(flagging as D2 only since I haven't tested with D1 -- quite possibly broken with both)
Comment #1 by leandro.lucarella — 2010-07-27T06:42:08Z
(In reply to comment #0)
> (flagging as D2 only since I haven't tested with D1 -- quite possibly broken
> with both)
Nope, D2-only (at least svn r584 works).
Comment #2 by clugdbug — 2010-07-27T07:31:12Z
(In reply to comment #1)
> (In reply to comment #0)
> > (flagging as D2 only since I haven't tested with D1 -- quite possibly broken
> > with both)
>
> Nope, D2-only (at least svn r584 works).
It failed up to D1.053. It works in D1.054 and later. Interestingly it also worked in D2.038 and 2.039 ONLY (released with 1.054), it had failed in 2.037 and earlier, but failed again starting with 2.040.
Comment #3 by dfj1esp02 — 2010-07-28T11:41:50Z
See bug 1160
Comment #4 by clugdbug — 2010-08-06T02:23:31Z
The fix to bug 1160 was what originally fixed it (in toBasetype(), do full semantic on the enum type when forward referenced); the fix to bug 3723 broke it again (in toBasetype(), only do semantic on the type, not on the full enum). In this situation, it does actually does the need the full semantic to be run.
Although this test case passes in D1, I'm not convinced that D1 is correct (it doesn't check for forward references at all).
----
PATCH: mtype.c, line 6340.
int TypeEnum::isZeroInit(Loc loc)
{
+ if (!sym->defaultval && sym->scope)
+ { // Enum is forward referenced. We need to resolve the whole thing.
+ sym->semantic(NULL);
+ }
if (!sym->defaultval)
{
#ifdef DEBUG
printf("3: ");
#endif
error(loc, "enum %s is forward referenced", sym->toChars());
return 0;
}
return sym->defaultval->isBool(FALSE);
}