+clean

Reduced test case:

//+
auto setFields_aux(bool isRef, alias foo, string s, T...)(T args)
{
    //import std.array : split;
    //import std.conv : to;
    //enum namesCall = split(s, ",");
    //pragma(msg, namesCall);
    enum namesCall = ["z", "x"];

    static assert(namesCall.length == T.length);
    static if (isRef)
    {
        enum foo2_name = "foo";
    }
    else
    {
        auto foo2 = foo;
        enum foo2_name = "foo2";
    }

    string getString()
    {
        string ret;
        foreach (i, vali ; namesCall)
        {
            ret ~= foo2_name ~ `.` ~ vali ~ `=` ~ `args[` ~ [cast(char)('0'+i)]/*i.to!string*/ ~ `];`;
        }
        ret ~= `return ` ~ foo2_name ~ `;`;
        return ret;
    }
    mixin(getString());
}

private struct Proxy(bool isRef, alias func, string parameters, Args ...)
{
    private static string addParameter(string parameters, string newParameter)()
    {
        return parameters is null ? newParameter : parameters ~ "," ~ newParameter;
    }

    Args args;
    this(int dummy, Args args)
    {
        static if (Args.length)
            this.args = args;
    }

    auto opDispatch(string name, T) (T value)
    {
        return Proxy!(isRef, func, addParameter!(parameters, name), Args, T)(0, args, value);
    }

    auto opCall()()
    {
        return setFields_aux!(isRef, func, parameters)(args);
    }
}

auto setfields(T)(T a)
{
    return Proxy!(true, a, null)(0);
}
auto setfields(T)()
{
    T a;
    return Proxy!(true, a, null)(0);
}

void main()
{
    struct A
    {
        int x;
        float y=10;
        string z;
    }

    auto z1 = A.init.setfields.z("a").x(3)();
    auto z2 = setfields!A.z("a").x(3)();
}
// +/

/+
struct Proxy(bool isRef, alias func, string parameters, Args ...)
{
    int dummy;
}

auto setfields(T)(T a)
{
    return Proxy!(true, a, null)(0);
    pragma(msg, "1: " ~ Proxy!(true, a, null).mangleof);
}
auto setfields(T)()
{
    T a;
    pragma(msg, "2: " ~ Proxy!(true, a, null).mangleof);
    return Proxy!(true, a, null)(0);
}

void main()
{
    struct A
    {
        int x;
        float y = 10;
        string z;
    }

    auto z1 = setfields(A.init);
    auto z2 = setfields!A();
}
// +/