D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6285 - switch-case statement fails for enums of strings
Summary: switch-case statement fails for enums of strings
Status: RESOLVED DUPLICATE of issue 2950
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Mac OS X
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-10 13:59 UTC by Blazej Podsiadlo
Modified: 2011-07-10 14:18 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Blazej Podsiadlo 2011-07-10 13:59:13 UTC
Hi,
Switch-case statement fails for enums of strings because it is not of integral type.

For the following code:
enum strEnum : string {strA = "strA", strB = "strB"};

strEnum se = strEnum.strA;
switch (strEnum) {
	case strEnum.strA: break;
};

I get the error message:
Error: 'strEnum' is not of integral type, it is a strEnum

In the same moment, I can workaround that by:
string realStr = strEnum.strA;
switch (realStr) {
	case strEnum.strA: break;
};

Unfortunately it doesn't help in my case where I want use final switch:  

final switch (strEnum) {
	case strEnum.strA: break;
	case strEnum.strB: break;
};

Best Regards
Blazej
Comment 1 kennytm 2011-07-10 14:18:36 UTC

*** This issue has been marked as a duplicate of issue 2950 ***