On Tuesday, 25 August 2015 at 18:19:40 UTC, tchaloupka wrote:
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. What to do then?

I think this is a bug, but is easily worked around with:

auto test(string a) {
    return .test(a, "b");
}

I suspect that the reason the error occurs, is that the auto return type automatically rewrites the function declaration into an eponymous template declaration. Since this creates a new naming scope, "test" by itself will only match the declaration inside the eponymous template. Forcing the compiler to look on the module level will force it to perform overload resolution.

Reply via email to