On Thursday, 15 August 2013 at 12:44:09 UTC, Tommi wrote:
I don't expect int[3] to implicitly convert to int[] during
type deduction for the same reason that I don't expect int to
implicitly convert to long during type deduction (even though I
know that int implicitly converts to long in all kinds of other
contexts):
void getLong(T)(T arg)
if (is(T == long))
{
}
void main()
{
int n;
getLong(n); // int doesn't implicitly convert to long
}
OK,
void getLong(T)(T arg)
if (is(T : long))
{
}
void main()
{
int n;
getLong(n); // int is implicitly convertible to long
}
now you have "implicit conversion from int to long during type
deduction".
Also actual conversion happens later in some completely
unrelated to type deduction compiler part.
I know implicit conversion happens at a later stage (not during
type deduction). But I don't have any other words to describe
it other than saying "implicit conversion during type
deduction". If you can provide me some more exact language,
please do.
There is a test whether base types are equal (which happens in
many stages, including type deduction) and conversion which
happens in later stage.
Compiler "doesn't give the benefit to doubt" as there are no
hints here about dynamic array.
Why would the compiler need a hint? The compiler knows that the
static array can implicitly convert to dynamic array, so it
should be able to check if the function could be called with
the argument first implicitly converted to a dynamic array.
Because I was speaking about general case. In this case yes, dmd
can know beforehand that T[N] can be converted to T[]. In general
case which can involve alias this (including multiple alias this)
the problem can be more complex.