auto foo() { if (1) { return [0, 0]; } else { size_t one; size_t two; return [one, two]; } } void main(){ } Error: mismatched function return type inference of uint[] and int[] A sufficiently smart compiler could figure out a common type for the two arrays. :)
Still present in git HEAD.
Hmm actually it's better if this is explicit. Otherwise the compiler may end up changing the return type if it finds a better type which all the return expressions implicitly convert to. For example: ----- auto foo() { if (0) { return [long.max]; } else { return [int.max + 1]; } } ----- Currently it's an error. In theory the compiler could decide to make the return type `long[]`, that would make the second array contain a positive long integer. *But*, if you remove the first expression the compiler will infer the return type as `int[]` and the second array will contain a negative number (due to signed int wraparound). I feel it would be a little dangerous to have such implicit type deduction matching in place. I'm marking my enhancement request as wontfix.