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
- d-bugmail puremagic.com (39/39) Apr 08 2007 http://d.puremagic.com/issues/show_bug.cgi?id=1111
- d-bugmail puremagic.com (9/9) Jan 01 2008 http://d.puremagic.com/issues/show_bug.cgi?id=1111
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
http://d.puremagic.com/issues/show_bug.cgi?id=1111 matti.niemenmaa+dbugzilla iki.fi changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |FIXED ------- Comment #1 from matti.niemenmaa+dbugzilla iki.fi 2008-01-01 11:22 ------- Fixed in DMD 1.025. --
Jan 01 2008