Created
June 14, 2011 18:27
-
-
Save schtibe/1025518 to your computer and use it in GitHub Desktop.
MyTypeing in OOPLSS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A { | |
def __construct(x: Int) { | |
self.x = x; | |
} | |
def m(): MyType { | |
return self; | |
} | |
def n(): MyType { | |
return self; | |
} | |
var x: Int; | |
var y: MyType; | |
} | |
class B { | |
def __construct(s: String) { | |
self.s = s; | |
} | |
def o(): MyType { | |
return self; | |
} | |
var s: String; | |
var k: MyType; | |
} | |
class C subtypeOf A subclassOf B { | |
def __construct(): A(5), B("Foo") { | |
} | |
def p(): Void { | |
k = k.k; // OK | |
k = self.k; // OK | |
//k = m(); // Fail | |
//k = B.k; // Fail | |
//k = s; // OK -- Diese Richtung darf nicht gehen | |
//s = k; // Fail -- Diese schon | |
//y = y; // Fail | |
y = y.y; // OK | |
//y = A.y; // Fail | |
//x = A.m().m().x; // Fail | |
//x = A.m().x; // Fail | |
x = A.x; // OK | |
x = 3; // OK | |
//B.s = B.o().s; // Fail | |
B.s = B.s; // OK | |
B.s = "foo"; // OK | |
} | |
def m(): MyType { | |
return self; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment