import std.stdio;
void foo(bool b) { writeln("bool"); }
void foo(int i) { writeln("int"); }
enum Boo : int {
a = 1,
b = 2,
}
void main() {
foo(Boo.a); //prints 'bool', should print int
foo(Boo.b); //prints 'int' correctly
}
This issue is related to http://d.puremagic.com/issues/show_bug.cgi?id=9999
Comment #1 by maxim — 2013-07-07T00:21:26Z
This is a separate issue. Boo should be Boo in the first place and int in the second. In referenced issue bool and long are overloaded, here are bool and int. If you pass 1 in such case int version should be called. Problem here is that int was converted to bool and passed to bool overload instead of int which is a bug.
Comment #2 by yazan.dabain — 2013-07-07T13:44:11Z
I certainly agree. I just wanted to note the explanation on why an int 'literal' of 1 would match a bool overload in the first place.
Comment #5 by razvan.nitu1305 — 2019-06-25T15:37:51Z
Upon discussion with Andrei, an enumerated value is not a literal, hence it is subject to regular type checking and cannot be polysemous. See also https://issues.dlang.org/show_bug.cgi?id=19399 which is causing trouble in industrial application.
Comment #6 by dlang-bot — 2019-06-27T13:12:25Z
@RazvanN7 created dlang/dmd pull request #10099 "Fix Issues 19399 and 10560 - Different Conversion Rules for Same Value and Type Enum" fixing this issue:
- Fix Issues 19399 and 10560 - Different Conversion Rules for Same Value and Type Enum
https://github.com/dlang/dmd/pull/10099