[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 at puremagic.com
d-bugmail at puremagic.com
Sun Apr 8 09:43:38 PDT 2007
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 at digitalmars.com
ReportedBy: deewiant at 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.
--
More information about the Digitalmars-d-bugs
mailing list