auto x(int z) {
if (z == 1) {
return x(z); //line 3
} else {
return z; //line 5
}
}
z.d(3): Error: forward reference to x
z.d(5): Error: mismatched function return type inference of int and _error_
It works when you switch line 3 and 5.
Comment #1 by bugzilla — 2011-04-03T22:12:01Z
This one is a little hard to fix, because the semantic analysis for function bodies goes statement by statement in a forward manner.
Comment #2 by bearophile_hugs — 2011-04-04T11:54:27Z
(In reply to comment #1)
> This one is a little hard to fix, because the semantic analysis for function
> bodies goes statement by statement in a forward manner.
This is a nice bug report, and to solve this kind of code the D compiler probably needs a little more powerful type inference. If you are able to do this improvement with a reasonable amount of work and code, then it's OK. Otherwise an option it to mark this with WONTFIX to keep the D compiler simpler. A better type inferencer may require more compilation time and a bigger compiler.