On Tuesday, 15 May 2018 at 14:52:46 UTC, Steven Schveighoffer wrote:
[snip]

It seems opDispatch isn't being used in the with statement. That seems like a bug, or maybe a limitation. I'm not sure how "with" works, but I assumed it would try calling as a member, and then if it doesn't work, try the call normally. Probably it's checking to see if it has that member first.

Annoying...

-Steve

Looks like with statements ignore opDispatch.

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


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

Reply via email to