I've encountered an issue using the 'with' statement. Can anyone explain why the following requires that I explicitly specify the variable name, even though it is within a 'with'?

class Foo {
    auto test(alias val)() if (is(typeof(val) == int)){}
    auto test(alias val)() if (!is(typeof(val) == int)){}
}

void main() {

    auto bar = new Foo;

    with (bar) {
        //test!2();        //fails to compile
        //test!"cats"();   //fails to compile
        bar.test!2();      //works
        bar.test!"cats"(); //works
    }
}

The commented out lines fail with:
Error: need 'this' for 'test' of type 'pure nothrow @safe void()'

Thanks

Reply via email to