https://issues.dlang.org/show_bug.cgi?id=19399
--- Comment #9 from Walter Bright <[email protected]> --- (In reply to Sprink from comment #0) > void foo(byte v) { writeln("byte ", v); } > void foo(int v) { writeln("int ", v); } > > enum A : int { > a = 127, > b = 128, // shh just ignore this > } > > void main() > { > A v = A.a; > foo(A.a); // byte 127 > foo(v); // int 127 should be byte 127 > } foo(A.a) is passing an integer literal of type enum and value 127. 127 can be implicitly converted to both byte and int, so foo(byte) and foo(int) both match with conversion level 2. Partial ordering selects foo(byte). foo(v) is passing an integer variable of type enum with a base type of int. This cannot be implicitly converted to byte, but it can be implicitly converted to int. Hence, foo(int) is selected. Partial ordering does not come into play. Note that the compiler explicitly does NOT do data flow analysis in the front end to determine that v is 127. The compiler is working correctly as the language is designed. --
