1111 – enum value referred to by another value of same enum is considered as enum's base type, not enum type

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1111 - enum value referred to by another value of same enum is considered as enum's base type, not enum type
Summary: enum value referred to by another value of same enum is considered as enum's ...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Windows
: P3 minor
Assignee: Walter Bright
URL:
Keywords: rejects-valid
Depends on:
Blocks:
Reported: 2007年04月08日 11:43 UTC by Matti Niemenmaa
Modified: 2014年02月16日 15:26 UTC (History)
0 users

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Matti Niemenmaa 2007年04月08日 11:43:37 UTC
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.
Comment 1 Matti Niemenmaa 2008年01月01日 11:22:06 UTC
Fixed in DMD 1.025.


AltStyle によって変換されたページ (->オリジナル) /