[Issue 18831] New: Weird interaction between std.variant, std.algorithm.iteration.map, and alias this

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun May 6 04:20:42 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=18831

          Issue ID: 18831
           Summary: Weird interaction between std.variant,
                    std.algorithm.iteration.map, and alias this
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody at puremagic.com
          Reporter: dhasenan at gmail.com

---
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)

--


More information about the Digitalmars-d-bugs mailing list