[Issue 16586] New: Implicit casting of enum with explicit int base type fails
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Mon Oct 3 15:08:43 PDT 2016
https://issues.dlang.org/show_bug.cgi?id=16586
Issue ID: 16586
Summary: Implicit casting of enum with explicit int base type
fails
Product: D
Version: D2
Hardware: x86_64
OS: Windows
Status: NEW
Severity: enhancement
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: m.bierlee at lostmoment.com
Consider the following code:
enum StringTypeEnumOne : string {
bla = "bla"
}
enum StringTypeEnumTwo : string {
bleh = "bleh"
}
enum IntTypeEnumOne : int {
bla = 1
}
enum IntTypeEnumTwo : int {
bleh = 2
}
public void main() {
string[] strings = [StringTypeEnumOne.bla, StringTypeEnumTwo.bleh];
int[] ints = [IntTypeEnumOne.bla, IntTypeEnumTwo.bleh];
}
When compiled the following compilation error is thrown:
src\app.d(19,16): Error: cannot implicitly convert expression
(cast(IntTypeEnumOne)1) of type IntTypeEnumOne to IntTypeEnumTwo
The string members are implicitly cast just fine, however I also expected the
members of the int enum to be cast implicitly because I explicitly defined the
base type of the enum.
--
More information about the Digitalmars-d-bugs
mailing list