[Issue 1182] Mixins scope

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Apr 27 00:34:47 PDT 2007


http://d.puremagic.com/issues/show_bug.cgi?id=1182





------- Comment #6 from aarti at interia.pl  2007-04-27 02:34 -------
It seems that your example works just because there is template function used.
In general case it fails, so it is no solution to problem. Consider following
example:

import std.stdio;
template TestTemplate() {
    int policy() { return 0; }
    int policy(int a) { return 1;}
    int policy(int a, int b) { return 2;}
}
class TestClass {
    mixin TestTemplate!() foo;
    alias foo.policy policy;
    int policy(int a) { return 11; }
}
void main() {
    writefln((new TestClass).policy);       //(1) Ok.
    //writefln((new TestClass).policy(1));  //(2) ambiguity
    writefln((new TestClass).policy(1,1));  //(3) Ok.
}

It would be possible to overcome this if you could alias specific symbol
/method e.g.: 

alias foo.policy(int, int) policy;

It seems that best solution is to extend rules of symbol matching. I would be
happy to see it also in case of inheritance (see thread on bugs NG).


-- 



More information about the Digitalmars-d-bugs mailing list