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.
Comment #4 by k.hara.pg — 2013-12-12T17:26:22Z
Comment #5 by github-bugzilla — 2013-12-12T20:27:43Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/65d3e9019f1f06a436ff3f8d922d63df7bc7479b fix Issue 11727 - Repeated error message with using forward referenced enum as variable https://github.com/D-Programming-Language/dmd/commit/a5ae10d83cef074c93e25c174b3d80536eae700a Merge pull request #2956 from 9rnsr/fix11727 [diag] Issue 11727 - Repeated error message with using forward referenced enum as variable
Comment #6 by k.hara.pg — 2013-12-12T20:31:15Z
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