Bug 2950 – Switch for enum : string fails

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2009-05-07T04:40:00Z
Last change time
2013-06-09T19:20:38Z
Keywords
pull, rejects-valid
Assigned to
andrej.mitrovich
Creator
temiy

Attachments

IDFilenameSummaryContent-TypeSize
1157Fix2950.patchPartial patchtext/plain1728

Comments

Comment #0 by temiy — 2009-05-07T04:40:25Z
enum TestEnum : string { f = "first", s = "second", t = "third" } void main () { TestEnum en = TestEnum.s; switch (en) { case TestEnum.f: break; case TestEnum.s: break; case TestEnum.t: break; } } enumBug.d(10): Error: Integer constant expression expected instead of "first" enumBug.d(12): Error: Integer constant expression expected instead of "second" enumBug.d(14): Error: Integer constant expression expected instead of "third"
Comment #1 by tomeksowi — 2010-10-22T14:02:22Z
*** Issue 4670 has been marked as a duplicate of this issue. ***
Comment #2 by kennytm — 2011-07-10T14:18:36Z
*** Issue 6285 has been marked as a duplicate of this issue. ***
Comment #3 by andrej.mitrovich — 2012-10-26T16:20:10Z
Created attachment 1157 Partial patch Partial patch against commit 6c01188d71433508bc4c0af6b821a97e8df2e986 The problem is this won't compile with -g option. When `EnumDeclaration::toDebug` is called, it calls cv4_Denum, which expects the enum to have an integer base type. It tries to call `toInteger` method on the enum declaration. `cv4_Denum` is a complicated function, I don't know how to implement a fix there.
Comment #4 by andrej.mitrovich — 2012-12-08T09:22:38Z
Comment #5 by andrej.mitrovich — 2013-02-04T18:18:02Z
Comment #6 by andrej.mitrovich — 2013-06-09T19:20:38Z
*** This issue has been marked as a duplicate of issue 10113 ***