assemblyscript/tests/compiler/call-super.ts

109 lines
1.3 KiB
TypeScript
Raw Normal View History

2019-02-02 16:03:21 +01:00
// both constructors present
2019-01-31 10:35:49 +01:00
class A {
a: i32 = 1;
constructor() {
assert(this.a == 1);
}
}
class B extends A {
// a: i32 = 3; // FIXME: currently duplicate identifier
b: i32 = 2;
constructor() {
super();
assert(this.a == 1);
assert(this.b == 2);
}
}
function test1(): void {
var b = new B();
assert(b.a == 1);
assert(b.b == 2);
}
test1();
2019-02-02 16:03:21 +01:00
// this constructor present
2019-01-31 10:35:49 +01:00
class C {
a: i32 = 1;
}
class D extends C {
b: i32 = 2;
constructor() {
super();
assert(this.a == 1);
assert(this.b == 2);
}
}
function test2(): void {
var d = new D();
assert(d.a == 1);
assert(d.b == 2);
}
test2();
2019-02-02 16:03:21 +01:00
// super constructor present
2019-01-31 10:35:49 +01:00
class E {
a: i32 = 1;
constructor() {
assert(this.a == 1);
}
}
class F extends E {
b: i32 = 2;
}
function test3(): void {
var f = new F();
assert(f.a == 1);
2019-02-02 16:03:21 +01:00
assert(f.b == 2);
2019-01-31 10:35:49 +01:00
}
test3();
2019-02-02 16:03:21 +01:00
// no constructor present
class G {
a: i32 = 1;
}
class H extends G {
b: i32 = 2;
}
function test4(): void {
var h = new H();
assert(h.a == 1);
assert(h.b == 2);
}
test4();
// this constructor present with fallback allocation (`this` is not accessed)
class I {
a: i32 = 1;
constructor() {
}
}
class J extends I {
b: i32 = 2;
}
function test5(): void {
var h = new J();
assert(h.a == 1);
assert(h.b == 2);
}
test5();