import std.stdio; import std.range : chain; auto test(string a) { return test(a, "b"); } auto test(string a, string b) { return chain(a, b); } void main() { writeln(test(a)); } Ends with: Error: forward reference to inferred return type of function call 'test' I know this exact sample is solvable by default parameter but there are cases where it is not possible. Workaround is discussed here: http://forum.dlang.org/post/cyvekwuwskhexribcbbl@forum.dlang.org
Minimal example: auto foo(){ return foo(0); } int foo(int x){ return x; } (Also, the original post has a typo, I suspect main should do writeln(test("a")).)
(In reply to timon.gehr from comment #1) > auto foo(){ return foo(0); } > int foo(int x){ return x; } This appears to be a regression (introduced in DMD 2.031).
https://github.com/D-Programming-Language/dmd/pull/5202
Recursive example: auto guessreturn(uint i) { if (i == 0) return 0; else return guessreturn(i-1); }
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/4b6779d2ff0b95866205189cb55e5aef00c13c7e fix Issue 14965 - Forward reference to inferred return type of function call when using auto return type If a function symbol is used, its overload resolution should be deferred until: ```d func(...) // CallExp.semantic func.mangleof // DotIdExp.semanticY typeof(func) // TypeTypeof.resolve typeof(&func) // TypeTypeof.resolve auto v = &func; // ExpInitializer.inferType &func; // ExpStatement.semantic return &func; // ReturnStatement ``` When the semantic analysis reaches to them, the function forward reference can beome actual error. Other use of 'func' should be treated as a property-like function call (done in `resolveProperties`) and finally handled in `CallExp`. https://github.com/D-Programming-Language/dmd/commit/624ad66c0bbfdfad8c5c1fc95339f77ac3659694 Merge pull request #5202 from 9rnsr/fix14965 [REG2.031] Issue 14965 - Forward reference to inferred return type of function call when using auto return type