digitalmars.D.bugs - mixin scope/overload
- Ant (42/43) Jun 12 2004 Is this a bug or not how it's suppose to be used?
- J Anderson (12/59) Jun 16 2004 Solution:
- Ant (5/25) Jun 16 2004 thank you.
- J Anderson (5/40) Jun 16 2004 The way it works now appears to be correct because a mixin has its own
- Ant (11/18) Jun 16 2004 Can't access the outer scope?
Is this a bug or not how it's suppose to be used? according to the docs: "mixin's body is evaluated within the scope where the mixin appears" so I expect the example to be valid. if method foo(int) is renamed to bar(int) compiles and runs if the mixin is not used and the method is copied to the class it compiles and runs. template M() { void foo(int i) { double d = i; foo(d); } } interface I { void foo(int i); void foo(double d); } class A : I { mixin M; void foo(double d) { printf("i = %f\n", d); } } int main(char[][] args) { A a = new A; a.foo(14); return 0; }dmd M.d -I~/dmd/src/phobosM.d(6): function foo (int i) does not match argument types (double) M.d(6): cannot implicitly convert double to int
Jun 12 2004
Ant wrote:Is this a bug or not how it's suppose to be used? according to the docs: "mixin's body is evaluated within the scope where the mixin appears" so I expect the example to be valid. if method foo(int) is renamed to bar(int) compiles and runs if the mixin is not used and the method is copied to the class it compiles and runs. template M() { void foo(int i) { double d = i; foo(d); } } interface I { void foo(int i); void foo(double d); } class A : I { mixin M; void foo(double d) { printf("i = %f\n", d); } } int main(char[][] args) { A a = new A; a.foo(14); return 0; }Solution: template M() { void foo(int i) { double d = i; this.foo(d); //this line } } -- -Anderson: http://badmama.com.au/~anderson/dmd M.d -I~/dmd/src/phobosM.d(6): function foo (int i) does not match argument types (double) M.d(6): cannot implicitly convert double to int
Jun 16 2004
In article <cap51m$2bcb$1 digitaldaemon.com>, J Anderson says...Ant wrote:thank you. But I would call that a workaround not a definitive solution. Is this suppouse to be "fixed" or will it stay like it is now? Anttemplate M() { void foo(int i) { double d = i; foo(d); } }Solution: template M() { void foo(int i) { double d = i; this.foo(d); //this line } }
Jun 16 2004
Ant wrote:In article <cap51m$2bcb$1 digitaldaemon.com>, J Anderson says...The way it works now appears to be correct because a mixin has its own scope as it says in the documentation. -- -Anderson: http://badmama.com.au/~anderson/Ant wrote:thank you. But I would call that a workaround not a definitive solution. Is this suppouse to be "fixed" or will it stay like it is now? Anttemplate M() { void foo(int i) { double d = i; foo(d); } }Solution: template M() { void foo(int i) { double d = i; this.foo(d); //this line } }
Jun 16 2004
On Thu, 17 Jun 2004 10:05:23 +0800, J Anderson wrote:Ant wrote:Can't access the outer scope? sorry, makes no sense. Besides there are examples of that on the docs. if that's how it's suppouse to be I propose that it's changed. What about when of the methods is renamed? does the scope changes with the name of the methods. This looks to me like another example of the problem with overloading. Ant PS this sounds curt in a bad way, sorry it's not my intention.In article <cap51m$2bcb$1 digitaldaemon.com>, J Anderson says...The way it works now appears to be correct because a mixin has its own scope as it says in the documentation.
Jun 16 2004