www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - mixin scope/overload

reply Ant <duitoolkit yahoo.ca> writes:
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/phobos

M.d(6): cannot implicitly convert double to int
Jun 12 2004
parent reply J Anderson <REMOVEanderson badmama.com.au> writes:
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;
}
#########
  

dmd M.d -I~/dmd/src/phobos
    

M.d(6): cannot implicitly convert double to int

template M() { void foo(int i) { double d = i; this.foo(d); //this line } } -- -Anderson: http://badmama.com.au/~anderson/
Jun 16 2004
parent reply Ant <Ant_member pathlink.com> writes:
In article <cap51m$2bcb$1 digitaldaemon.com>, J Anderson says...
Ant wrote:
##########
template M()
{
	void foo(int i)
	{
		double d = i;
		foo(d);
	}
}

template M() { void foo(int i) { double d = i; this.foo(d); //this line } }

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? Ant
Jun 16 2004
parent reply J Anderson <REMOVEanderson badmama.com.au> writes:
Ant wrote:

In article <cap51m$2bcb$1 digitaldaemon.com>, J Anderson says...
  

Ant wrote:
    

##########
template M()
{
	void foo(int i)
	{
		double d = i;
		foo(d);
	}
}

      

template M() { void foo(int i) { double d = i; this.foo(d); //this line } }

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? Ant

scope as it says in the documentation. -- -Anderson: http://badmama.com.au/~anderson/
Jun 16 2004
parent Ant <duitoolkit yahoo.ca> writes:
On Thu, 17 Jun 2004 10:05:23 +0800, J Anderson wrote:

 Ant wrote:
 
In article <cap51m$2bcb$1 digitaldaemon.com>, J Anderson says...
  

scope as it says in the documentation.

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.
Jun 16 2004