Following code doesn't work: ---------------------------- import std.stdio; class Foo { void opDispatch(string name)() { writeln(name); } } void main() { auto foo = new Foo; with (foo) { bar(); } } ---------------------------- Result: $ dmd -run main main.d(16): Error: undefined identifier bar ---------------------------- According to the specifications, WithStatement should be interpreted as follows: ---- with (foo) { bar(); } ---- is semantically equivalent to: Foo tmp = foo; tmp.bar(); ---- is semantically equivalent to: Foo tmp = foo; tmp.opDispatch!("bar")(); ---- It is incorrect behavior and is a bug. And another thing, this syntax is simply convenient if I could use opDispatch in WithStatement.
Not working on 2.059
*** Issue 9808 has been marked as a duplicate of this issue. ***
Just ran into this issue. From a cursory look at DMD's source code, I noticed that WithStatement::semantic was adding the symbol's scope before calling body->semantic, which means WithStatement has the same scoping rules as a method. This means that the problem is that opDispatch doesn't work in symbol scope: ---------------- struct A { void opDispatch(string Value)() { pragma(msg, Value); } void test() { // works this.hello; // NG hello; } } ---------------- I'm unsure as to whether this is intended behaviour or not, but resolving the opDispatch scope issue would also resolve this issue.
I've also ran into this issue...
I have also hit this.
It would be very awesome if this was resolved. Both `opDispatch` and `with` are under-appreciated parts of the language with a lot of potential.
This is likely the same problem as Issue 8000. I add my voice to ask this be resolved.
Covered by DMD's PR https://github.com/dlang/dmd/pull/6439
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/2c8008781a23f807be89dfaf858814a1308c9f43 Fix issue 6400 - Better interaction between with() and opDispatch https://github.com/dlang/dmd/commit/c49fb860d507f75556cfb2108986a8b901d15920 Merge pull request #6439 from LemonBoy/b6400 Fix issue 6400 - Better interaction between with() and opDispatch
Commits pushed to newCTFE at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/2c8008781a23f807be89dfaf858814a1308c9f43 Fix issue 6400 - Better interaction between with() and opDispatch https://github.com/dlang/dmd/commit/c49fb860d507f75556cfb2108986a8b901d15920 Merge pull request #6439 from LemonBoy/b6400
Commits pushed to stable at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/2c8008781a23f807be89dfaf858814a1308c9f43 Fix issue 6400 - Better interaction between with() and opDispatch https://github.com/dlang/dmd/commit/c49fb860d507f75556cfb2108986a8b901d15920 Merge pull request #6439 from LemonBoy/b6400
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/4dfa27ecb16639044961ad995a32352111c19edc Fix issue 6400 - Better interaction between with() and opDispatch (Part 2) https://github.com/dlang/dmd/commit/c5defc80b321d8573789279c59161aaa3f3e3654 Merge pull request #7356 from JinShil/fix_6400 Fix issue 6400 - Better interaction between with() and opDispatch (Part 2) merged-on-behalf-of: Mike Franklin <JinShil@users.noreply.github.com>
Commits pushed to stable at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/4dfa27ecb16639044961ad995a32352111c19edc Fix issue 6400 - Better interaction between with() and opDispatch (Part 2) https://github.com/dlang/dmd/commit/c5defc80b321d8573789279c59161aaa3f3e3654 Merge pull request #7356 from JinShil/fix_6400