On 12/10/2013 08:29 AM, Kenji Hara wrote:
This is an intended behavior. An array literal has dynamic array type *by default*. But all of literals in D behave as polymorphic. char c = 'A'; // character literal has char type by default dchar d = 'A'; // but it may be implicitly typed as wchar/dchar string str = "hello"; dstring dstr = "hello"; // string literal is implicitly typed as dstring int[] darr = [1,2,3]; int[3] darr = [1,2,3]; // implicitly typed as int[3] So, an array literal [1,2,3] is implicitly convertible both to int[] and int[3]. And, int[3] is more specialized than int[], so overload resolution will choose the first 'bar'. Kenji Hara
Match with implicit conversion cannot be what is really happening as otherwise the following call would be ambiguous:
int bar(int[3] arr){ return 1; } int bar(double[] arr){ return 2; } int bar(int[] arr){ return 3; } static assert(bar([1,2,3])==1);