Thread overview | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
May 16, 2018 [Issue 18866] Overload from opDispatch ignored in WithStatement | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=18866 Mike Franklin <slavo5150@yahoo.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |slavo5150@yahoo.com --- Comment #1 from Mike Franklin <slavo5150@yahoo.com> --- This may have been introduced by https://github.com/dlang/dmd/pull/7356 -- |
May 16, 2018 [Issue 18866] Overload from opDispatch ignored in WithStatement | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=18866 --- Comment #2 from Mike Franklin <slavo5150@yahoo.com> --- Or actually it may be this PR that introduced the issue: https://github.com/dlang/dmd/pull/6439 -- |
May 28, 2018 [Issue 18866] Overload from opDispatch ignored in WithStatement | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=18866 RazvanN <razvan.nitu1305@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |razvan.nitu1305@gmail.com --- Comment #3 from RazvanN <razvan.nitu1305@gmail.com> --- I'm not sure if this bug report is valid. The current behavior might be a future. If this "bug" would be fixed there would be absolutely no way of calling fun1() from within the WithStatement body and that IMHO is an arbitrary limitation. As things stand now, the compiler first tries to resolve fun1 as a member of S1 and if that's not possible it goes up the enclosing scope. If the chain of scopes is over and fun1 still wasn't resolved then opDispatch is called. In my opinion this makes a lot more sense then calling opDispatch for every method that is not defined in the struct. -- |
May 28, 2018 [Issue 18866] Overload from opDispatch ignored in WithStatement | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=18866 --- Comment #4 from Simen Kjaeraas <simen.kjaras@gmail.com> --- > there would be absolutely no way of calling fun1() from within the WithStatement body Sure there would. Assuming the same code as in comment 0, you would call the global fun2 using .fun2();. You can test this by duplicating the line that calls fun2 and adding a period - it will print 'global'. There's no reason to assume that wouldn't work if an overload was available via opDispatch. -- |
November 16, 2018 [Issue 18866] Overload from opDispatch ignored in WithStatement | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=18866 John Hall <john.michael.hall@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |john.michael.hall@gmail.com --- Comment #5 from John Hall <john.michael.hall@gmail.com> --- I think a case can be made for fixing this. At a minimum, I think the spec is vague in this instance. On opDispatch it just says that things not found will be forwarded based on opDispatch. On the with statement it makes no reference to opDispatch, suggesting that opDispatch should happen first, rather than last. Moreover, the spec says "This is to reduce the risk of inadvertant breakage of with statements when new members are added to the object declaration." Below is the example from the documentation discussed in one of the PRs mentioned above. The behavior is totally changed if you add in a global function, e.g. void f() { writeln("f global"); } In other words, the way it currently operates raises the risk of inadvertant breakage when new global functions are added. So I think a case can be made for fixing this, or at least making the spec clearer about how with statements interact with opDispatch to make clear how it currently works. --- import std.stdio; struct Foo { void opDispatch(string name)() { mixin("writeln(\"Foo.opDispatch!" ~ name ~ "\");"); } } struct Bar { // `Bar` does not implement `f()` or `opDispatch` } void main() { Foo foo; Bar bar; with(foo) { f(); // prints "Foo.opDispatch!f" with(bar) { f(); // Prior to this Release: Error: undefined identifer `f` // Starting with this release: Prints "Foo.opDispatch!f". // `f`'s resolution is forwarded up the scope hierarchy. } } } --- -- |
November 16, 2018 [Issue 18866] Overload from opDispatch ignored in WithStatement | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=18866 --- Comment #6 from Simen Kjaeraas <simen.kjaras@gmail.com> --- (In reply to John Hall from comment #5) You're right that a new global function will shadow opDispatch, but with the fix the exact opposite problem will appear, so it's not all that simple. -- |
November 16, 2018 [Issue 18866] Overload from opDispatch ignored in WithStatement | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=18866 --- Comment #7 from John Hall <john.michael.hall@gmail.com> --- I get that. The point I wanted to highlight was that even if it's not changed at least the spec can be beefed up. -- |
January 15, 2019 [Issue 18866] Overload from opDispatch ignored in WithStatement | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=18866 Mike Franklin <slavo5150@yahoo.com> changed: What |Removed |Added ---------------------------------------------------------------------------- See Also| |https://issues.dlang.org/sh | |ow_bug.cgi?id=19588 -- |
December 17, 2022 [Issue 18866] Overload from opDispatch ignored in WithStatement | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=18866 Iain Buclaw <ibuclaw@gdcproject.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Priority|P1 |P3 -- |
February 17, 2023 [Issue 18866] Overload from opDispatch ignored in WithStatement | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=18866 Paul Backus <snarwin+bugzilla@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |snarwin+bugzilla@gmail.com --- Comment #8 from Paul Backus <snarwin+bugzilla@gmail.com> --- Another example, from the forums: --- enum Suit { clubs, spades, hearts, diamonds } struct Card { void opDispatch(string s)(.Suit) {} } void main() { Card c; with (c) Suit = .Suit.diamonds; // Error: `Suit` is not an lvalue and cannot be modified } --- It doesn't seem to matter whether the existing symbol is a function, a type, a variable, or anything else; or whether it's declared at module scope or locally. As long as any symbol with the requested name exists in any enclosing scope, the with statement will not call opDispatch. -- |
Copyright © 1999-2021 by the D Language Foundation