On Tuesday, 1 October 2013 at 17:35:07 UTC, Artur Skawina wrote:
The symbols are looked up in parent scope first, the implicit
conversion happens later.
I expected the compiler to check the aliasThis member right after
the current scope. The language reference only says, that
undefined lookups are forwarded to the aliasThis member. I think
it should be exactly like with template mixins:
import std.stdio, std.cstream;
mixin template Template() {
void foo() {
writeln("Template.foo");
}
}
class Class {
void foo() {
writeln("Class.foo");
}
}
class Outer {
void foo() {
writeln("Outer.foo");
}
class Inner {
static const bool mixinTemplate = false;
static if (mixinTemplate) {
mixin Template bar;
} else {
private Class bar = new Class;
alias bar this;
}
//void foo() {
// writeln("Inner.foo");
//}
void test() {
foo();
this.foo();
this.outer.foo();
bar.foo();
}
}
void test() {
Inner inner = new Inner;
inner.test();
}
}
void main(string[] args) {
Outer outer = new Outer;
outer.test();
din.getc();
}
mixinTemplate == true:
Template.foo
Template.foo
Outer.foo
Template.foo
mixinTemplate == false:
Outer.foo <-- should be Class.foo
Class.foo
Outer.foo
Class.foo
If the the inner class were static, mixinTemplate == false would
not compile.
aliasThis is just a dynamic mixin, right?
Eberhard.