'this' Typing

c foo(): C { return this; }

D bar(): D { return 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.

Last edited Jan 16, 2013 at 3:26 PM by jonturner, version 2

Comments

No comments yet.