'this' Typing
What if we allowed 'this' to also act as a type to reflect the current type of this.
class C {
f() {
var x: this;
var c: C;
c = x;
}
}
In short, we would enforce:
this <: C
Which would make the above:
class C<this extends C> {
f() {
var x: this;
var c: C;
c = x;
}
}
The subtype relationship would also disallow 'this' to be interchanged with the class type. This example would not be allowed:
class C<this extends C> {
f() {
var x = this;
x = new C();
}
}
because C is not assignment compatible with x, because x : this.