D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 10113 - Can't use an enum : string in a switch statement
Summary: Can't use an enum : string in a switch statement
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: pull
: 2950 (view as issue list)
Depends on:
Blocks:
 
Reported: 2013-05-17 23:39 UTC by Dylan Knutson
Modified: 2015-06-09 05:15 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Dylan Knutson 2013-05-17 23:39:09 UTC
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 Dylan Knutson 2013-05-18 00:11:41 UTC
Sorry; I forgot to include compiler info. 

> dmd --version
DMD v2.063 DEBUG
Comment 3 github-bugzilla 2013-06-09 19:13:01 UTC
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/abdccd46f3820f44b37b754dc15beed99fda4b96
fix issue 10113 - Can't use an enum : string in a switch statement

https://github.com/D-Programming-Language/dmd/commit/9b6fa5682c50d2b9674c1e5cb97672a4f7daa35b
Merge pull request #2080 from hpohl/10113

fix issue 10113 - Can't use an enum : string in a switch statement
Comment 4 Andrej Mitrovic 2013-06-09 19:20:38 UTC
*** Issue 2950 has been marked as a duplicate of this issue. ***
Comment 5 Andrej Mitrovic 2013-06-09 19:23:17 UTC
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 Andrej Mitrovic 2013-06-09 20:07:30 UTC
(In reply to comment #2)
> https://github.com/D-Programming-Language/dmd/pull/2080

Thanks, Henning. Keep up the good work!