Test case:
inout(V) get(K, V)(inout(V[K]) aa, K key, lazy inout(V) defaultValue)
{
auto p = key in aa;
return p ? *p : defaultValue;
}
void main()
{
short[short] aa = [1:10, 2:20];
short n = get(aa, 5, 50);
// IFTI should deduce K=short, V=short from the arguments
// !()(short[short], int, int)
// because 1 and 2 are implicitly convertible to short
// , and 10 and 20 are implicitly convertible to short
assert(n == 50);
}
(In reply to comment #3)
> Somewhat related to issue 4998
It's not related (and looks to me that would be impossible) issue.
Comment #5 by schveiguy — 2014-03-03T08:10:38Z
Definitely related. In both cases, the compiler is inferring the type of the literal based on the defined type of the literal rather than how it's used. In both cases, choosing a smaller integer type will satisfy the call, and should be done.
Yes, in 4998, the example does not provide enough information in the signature itself to figure out the correct type to use, which is why the proposal is given.