I think this is because inside the class Monitor, your class name doesn't quite exist yet so the compiler thinks the already existing Monitor (it is in object.d which is auto imported) is a better match.
I actually think this should be considered a compiler bug, since if the other Monitor didn't exist, this code would indeed work. edit: Actually, since Monitor is a nested class in Object, this is /not/ a compiler bug, nested names always override outer names. So it is just weird that Object base class has a nested one called Monitor. /edit
But to work around the thing for now, you can use typeof(this)
inside the Monitor class instead of its name. That will disambiguate inside, and the outside code still works correctly:
module app;
class Monitor {
// changed the name only inside the class
public typeof(this) returnMe() {
return this;
}
}
void main() {
// works normally here
Monitor monitor = new Monitor;
monitor.returnMe();
}