[Issue 19399] Different Conversion Rules for Same Value and Type -- Enum

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Feb 15 13:20:27 UTC 2019


https://issues.dlang.org/show_bug.cgi?id=19399

--- Comment #4 from David Eckardt <david.eckardt at frequenz.io> ---
The wrong overloaded function is picked with arrays as well. An array of
integers can be implicitly cast to char[]. This should not happen.


int f(const char[] str) {return 1;}
int f(const void[] data, int type_id) {return 2;}

assert(f("abc") == 1); // As expected.
assert(f("abc", 5) == 2); // As expected.

assert(f([1, 2, 3]) == 1); // Compiles - an array of integers matches
f(char[])?!
f([1, 2, 300]); // Error: None of the overloads of `f` matches, as expected

enum e = [4, 5, 6];
static assert(is(typeof(e) == int[])); // So we do have ints here...
assert(f(e) == 1);                     // ... and int[] matches f(char[])?!?

immutable a = e;
f(a, 7); // Compiles
f(a); // Error: None of the overloads of `f` matches, as expected

--


More information about the Digitalmars-d-bugs mailing list