https://issues.dlang.org/show_bug.cgi?id=5363
--- Comment #9 from Walter Bright <[email protected]> --- I simplified it a bit more, so it happens at compile time: struct S { int dummy; alias dummy this; } int foo(int){ return 1; } int foo(const(S)){ return 2; } void test() { static assert(foo(cast(const)S.init) == 2); // pass static assert(foo(S.init) == 2); // fail } Here's the trouble. With alias this, the conversion of S to int is considered an 'exact' match, while the conversion of S to const is considered a 'constant' match, which is not as good as 'exact'. Hence, the 'exact' is selected and foo(int) is called. The levels of conversion are: nomatch convert constant exact We could change an alias this conversion to a 'convert' match, but it is unknown how much breakage this will cause. It seems to be a rather drastic change. The compiler source code is the TypeStruct.implicitConvTo() function in mtype.d. --
