--- import std.variant, std.range, std.algorithm; struct Bar { int i; } struct Foo { auto i() { return iota(12) .map!(x => Bar(x)); } alias i this; } void main() { Foo controlGroup = Foo(); Algebraic!(Foo) treatmentGroup = Foo(); } --- The control group works without errors. The treatment group fails with: /home/dhasenan/.local/bin/../include/phobos/std/meta.d(799): Error: template instance `F!(__lambda1)` cannot use local __lambda1 as parameter to non-global template replaceTemplateArgs(T...) /home/dhasenan/.local/bin/../include/phobos/std/meta.d(805): Error: template instance `algebraicaliasthis.Foo.i.staticMap!(replaceTemplateArgs, __lambda1)` error instantiating /home/dhasenan/.local/bin/../include/phobos/std/typecons.d(7788): instantiated from here: staticMap!(replaceTemplateArgs, __lambda1, Result) /home/dhasenan/.local/bin/../include/phobos/std/variant.d(103): instantiated from here: ReplaceType!(This, VariantN!(1LU, Foo), Foo) /home/dhasenan/.local/bin/../include/phobos/std/variant.d(137): instantiated from here: This2Variant!(VariantN!(1LU, Foo), Foo) /home/dhasenan/.local/bin/../include/phobos/std/variant.d(1500): instantiated from here: VariantN!(1LU, Foo) algebraicaliasthis.d(20): instantiated from here: Algebraic!(Foo)
Some notes on paring it down: * Omitting the call to map makes this compile. * Omitting the alias this makes it compile. * You don't actually need a struct Bar; `map!(x => x)` is enough. * You can use an array instead of iota. * Replacing the lambda parameter with a top-level function (map!identity) changes the error to: /home/dhasenan/.local/bin/../include/phobos/std/typecons.d(7784): Error: function algebraicaliasthis.identity(string s) is not callable using argument types () /home/dhasenan/.local/bin/../include/phobos/std/meta.d(799): Error: template instance `std.typecons.ReplaceType!(This, VariantN!(1LU, Foo), Foo).F!(identity)` error instantiating /home/dhasenan/.local/bin/../include/phobos/std/meta.d(805): instantiated from here: staticMap!(replaceTemplateArgs, identity) /home/dhasenan/.local/bin/../include/phobos/std/typecons.d(7788): instantiated from here: staticMap!(replaceTemplateArgs, identity, string[]) /home/dhasenan/.local/bin/../include/phobos/std/variant.d(103): instantiated from here: ReplaceType!(This, VariantN!(1LU, Foo), Foo) /home/dhasenan/.local/bin/../include/phobos/std/variant.d(137): instantiated from here: This2Variant!(VariantN!(1LU, Foo), Foo) /home/dhasenan/.local/bin/../include/phobos/std/variant.d(1500): instantiated from here: VariantN!(1LU, Foo) algebraicaliasthis.d(16): instantiated from here: Algebraic!(Foo)
The given example compiles successfully as of DMD 2.092.1.