Bug 11727 – Repeated error message with using forward referenced enum as variable
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-12-11T19:06:00Z
Last change time
2013-12-12T20:31:15Z
Keywords
diagnostic, pull
Assigned to
nobody
Creator
monkeyworks12
Comments
Comment #0 by monkeyworks12 — 2013-12-11T19:06:48Z
auto returnEnum()
{
//Fails with "dmd: mtype.c:7620: virtual Type* TypeEnum::nextOf(): Assertion `sym->scope' failed."
//enum n;
enum n = 0; //Ok
return n;
}
void main()
{
assert(returnEnum() == 0);
}
Comment #1 by yebblies — 2013-12-12T03:51:16Z
I get:
DMD v2.065 DEBUG
testx.d(4): Error: enum testx.returnEnum.n is forward referenced looking for base type
testx.d(4): Error: enum testx.returnEnum.n is forward referenced looking for base type
testx.d(4): Error: enum testx.returnEnum.n is forward referenced looking for base type
testx.d(11): Error: incompatible types for ((returnEnum()) == (0)): 'n' and 'int'
With the latest compiler.
Comment #2 by monkeyworks12 — 2013-12-12T09:10:54Z
(In reply to comment #1)
> I get:
>
> DMD v2.065 DEBUG
> testx.d(4): Error: enum testx.returnEnum.n is forward referenced looking for
> base type
> testx.d(4): Error: enum testx.returnEnum.n is forward referenced looking for
> base type
> testx.d(4): Error: enum testx.returnEnum.n is forward referenced looking for
> base type
> testx.d(11): Error: incompatible types for ((returnEnum()) == (0)): 'n' and
> 'int'
>
> With the latest compiler.
My mistake, I tested this on Dpaste and must not have set it to Git HEAD. Still, should this be changed to rejects-valid? It seems to me that n should default to type int and value 0.
Comment #3 by yebblies — 2013-12-12T16:42:44Z
(In reply to comment #2)
>
> My mistake, I tested this on Dpaste and must not have set it to Git HEAD.
> Still, should this be changed to rejects-valid? It seems to me that n should
> default to type int and value 0.
enum n; isn't an enum variable with no value, it's a forward declaration of an enum type 'n'. (like "struct s;") Enum variables must always have an initializer.
The error message obviously could be improved.
Now the OP code:
auto returnEnum()
{
enum n;
return n; // Line 4
}
void main()
{
assert(returnEnum() == 0);
}
Prints:
test.d(4): Error: type n has no value