There is a wart in D I'd like to eliminate. Unfortunately, that would
also eliminate some valid uses.
The problem is as follows. "ref" values in function parameter lists are
always bound to lvalues - never rvalues. This is, except for _one_ case:
"this" in member functions.
struct A {
void fun() {
...
}
}
A gun() { return A(); }
unittest {
gun().fun(); // works
}
This doesn't sound so bad until the following happens:
struct A {
ref A opAssign(ref A rhs) { ... }
}
struct B {
@property A a() { ... }
}
unittest {
B b;
b.a = A.init;
}
Everything looks kosher, but the problem is b.a returns a temporary, and
then that temporary is assigned to. The assignment is inoperant.
For this and other related reasons I'd like to disallow binding
temporaries to "this". There are cases in which you'd want to, and you'd
have to insert explicit variables. But I think eliminating the binding
is the right thing to do.
Thoughts?
Andrei