Hi, I'm wondering about why this happens in a certain situation and not another. I have the following code:

struct Holder(alias fun) {
    alias T = typeof(fun());
    T get() { return fun(); }
    alias get this;
}

template match(handlers...) {
    auto match(T)(T holder) {
        return handlers[0](holder);
    }
}

void main() {
    int f() { return i7 }
    auto value = Holder!f().match!(
        (int a) => f()
    );
}

This compiles fine. However, if I change the match template to:

template match(handlers...) {
    auto match(alias f)(Holder!f holder) {
        return handlers[0](holder);
    }
}

Notice the template parameter of the eponymous match is an alias now, and the function parameter is typed as a Holder.

The error you get is basically because of bug 5710 [0] I guess. But I'm confused as to why the same thing doesn't then happen when using match(T) as opposed to match(alias f)?

I can work around it by have a template constraint on match of course. But still curious why one version works and the other not, they both have to access the same frame+context data at the end of the day.


[0]: https://issues.dlang.org/show_bug.cgi?id=5710

Reply via email to