On Sunday, 13 March 2016 at 02:33:49 UTC, Simen Kjaeraas wrote:
http://dpaste.dzfl.pl/7360ee90b344

Dammit, 3:30AM was apparently too late, and some bad code leaked through. I managed to sidestep a problem by writing nonsense code. The problem I get can be reduced to this:

struct S {
    void foo(alias a)() {}
}

unittest {
    S s;
    s.foo!((int i) => 1); // Works
    s.foo!(i => 1); // Fails
}

Result:
foo.d(8): Error: template instance foo!((i) => 1) cannot use local '__lambda1' as parameter to non-global template foo(alias a)()

Bah. It's in bugzilla as bug 5710[1] (with the most discussion), 3051, 3052, 11098, 12285, 12576 and 15564, and has a $150 bounty on bountysource:
https://www.bountysource.com/issues/1375082-cannot-use-delegates-as-parameters-to-non-global-template

Maybe it's time I learnt how DMD is put together and earn $150...


Now, there's a way to work around that, by putting the lambda in an intermediate type. Sadly, that runs afoul of bug 15794[2] for the typed lambda, so I'm stumped for now.

[1]: https://issues.dlang.org/show_bug.cgi?id=5710
[2]: https://issues.dlang.org/show_bug.cgi?id=15794

Reply via email to