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: [email protected]
          Reporter: [email protected]

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/[email protected]

--

Reply via email to