|
Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript electronics |
digitalmars.D.bugs - [Issue 1111] New: enum value referred to by another value of same enum is considered as enum's base type, not enum type
http://d.puremagic.com/issues/show_bug.cgi?id=1111 Summary: enum value referred to by another value of same enum is considered as enum's base type, not enum type Product: D Version: 1.010 Platform: PC OS/Version: Windows Status: NEW Keywords: rejects-valid Severity: minor Priority: P3 Component: DMD AssignedTo: bugzilla digitalmars.com ReportedBy: deewiant gmail.com A strange beetle, this, and difficult to summarize. Example code: enum Enum : byte { NORMAL_VALUE = 0, REFERRING_VALUE = NORMAL_VALUE + 1, OTHER_NORMAL_VALUE = 2 } void test(Enum e) { } void main() { test(Enum.NORMAL_VALUE); test(Enum.REFERRING_VALUE); test(Enum.OTHER_NORMAL_VALUE); } The call on line 11, passing Enum.NORMAL_VALUE, fails unless the definition of REFERRING_VALUE is changed to not refer to NORMAL_VALUE. Alternatively, set REFERRING_VALUE just equal to NORMAL_VALUE (remove the "+ 1"). The error: asdf.d(11): function asdf.test (Enum) does not match parameter types (byte) asdf.d(11): Error: cannot implicitly convert expression (0) of type byte to Enum Fortunately, this can be worked around by referring to Enum.NORMAL_VALUE, as opposed to just NORMAL_VALUE, in the definition of REFERRING_VALUE. This might have something to do with Issue 633: when NORMAL_VALUE is used in an expression, it is cast to Enum's base type, and left that way? This doesn't explain why using the fully qualified name of NORMAL_VALUE works, though. -- Apr 08 2007
|