Bug 6400 – opDispatch with WithStatement

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-07-29T08:31:01Z
Last change time
2017-12-18T22:57:53Z
Assigned to
No Owner
Creator
SHOO

Comments

Comment #0 by zan77137 — 2011-07-29T08:31:01Z
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.
Comment #1 by lovelydear — 2012-04-26T09:50:39Z
Not working on 2.059
Comment #2 by yebblies — 2015-02-06T05:17:53Z
*** Issue 9808 has been marked as a duplicate of this issue. ***
Comment #3 by me — 2015-07-18T06:30:19Z
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.
Comment #4 by luis — 2015-09-23T16:11:14Z
I've also ran into this issue...
Comment #5 by joeyemmons — 2015-10-04T08:28:04Z
I have also hit this.
Comment #6 by john.loughran.colvin — 2016-03-04T12:47:38Z
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.
Comment #7 by public2 — 2016-06-10T03:20:58Z
This is likely the same problem as Issue 8000. I add my voice to ask this be resolved.
Comment #8 by bitter.taste — 2017-01-13T21:17:52Z
Comment #9 by github-bugzilla — 2017-01-15T09:38:03Z
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
Comment #10 by github-bugzilla — 2017-01-16T23:26:39Z
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
Comment #11 by github-bugzilla — 2017-03-22T12:21:13Z
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
Comment #12 by github-bugzilla — 2017-12-06T04:11:47Z
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 <[email protected]>
Comment #13 by github-bugzilla — 2017-12-18T22:57:53Z
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