[Issue 18863] New: opDispatch with WithStatement & Template Instance

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue May 15 20:30:11 UTC 2018


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

          Issue ID: 18863
           Summary: opDispatch with WithStatement & Template Instance
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: john.michael.hall at gmail.com

The with statement does not check opDispatch with template instances. An older
bug (#6400) was resolved fixing the case of a symbol. This enhancement is for
template instances.

See below:

struct Foo(int x)
{
    auto opDispatch(string s)()
        if (s == "bar")
    {
        x++;
        return x;
    }
}


void main()
{
    int y = 0;
    with(Foo!1)
    {
        y = bar; //error: undefined identifier bar
    }
    assert(y == 2);
}

By contrast, the following compiles without error

struct Foo
{
    int x;
    auto opDispatch(string s)()
        if (s == "bar")
    {
        x++;
        return x;
    }
}


void main()
{
    int y = 0;
    with(Foo(1))
    {
        y = bar;
    }
    assert(y == 2);
}


Discussion thread:
https://forum.dlang.org/thread/becssptpaecvxddbrpbw@forum.dlang.org

--


More information about the Digitalmars-d-bugs mailing list