Bug 10113 – Can't use an enum : string in a switch statement
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-05-17T23:39:00Z
Last change time
2015-06-09T05:15:08Z
Keywords
pull
Assigned to
nobody
Creator
tcdknutson
Comments
Comment #0 by tcdknutson — 2013-05-17T23:39:09Z
Instances of an enum of type string can't be passed into a switch or final switch:
----
enum Test : string {
Foo = "Foo",
}
Test a = Test.Foo;
switch(a) {
case Test.Foo: break;
}
----
even though a string is a valid type to pass into a (final) switch.
Compiler error:
Error: 'a' must be of integral or string type, it is a Test
but obviously the underlying type of 'a' is string.
Comment #1 by tcdknutson — 2013-05-18T00:11:41Z
Sorry; I forgot to include compiler info.
> dmd --version
DMD v2.063 DEBUG
Comment #4 by andrej.mitrovich — 2013-06-09T19:20:38Z
*** Issue 2950 has been marked as a duplicate of this issue. ***
Comment #5 by andrej.mitrovich — 2013-06-09T19:23:17Z
Even though the pull didn't test this, the -g switch seems to work too. (in my pull this didn't work). It may be a good idea to add -g in the PERMUTE_ARGS section though, to avoid regressions.
Comment #6 by andrej.mitrovich — 2013-06-09T20:07:30Z