forked from AssemblyScript/assemblyscript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanaged-cast.ts
53 lines (44 loc) · 1.22 KB
/
managed-cast.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
class Animal {
tame(): void {}
}
class Cat extends Animal {
meow(): void {}
}
function testUpcast(cat: Cat): void {
(<Animal>cat).tame();
}
testUpcast(new Cat());
function testUpcastFromNullable(cat: Cat | null): void {
(<Animal>cat).tame();
}
testUpcastFromNullable(new Cat());
function testUpcastToNullable(cat: Cat): void {
var maybeAnimal = <Animal | null>cat;
if (maybeAnimal) maybeAnimal.tame();
}
testUpcastToNullable(new Cat());
function testUpcastFromToNullable(cat: Cat | null): void {
var maybeAnimal = <Animal | null>cat;
if (maybeAnimal) maybeAnimal.tame();
}
testUpcastFromToNullable(new Cat());
function testDowncast(animal: Animal): void {
(<Cat>animal).meow();
}
testDowncast(new Cat());
function testDowncastFromNullable(animal: Animal | null): void {
(<Cat>animal).meow();
}
testDowncastFromNullable(new Cat());
function testDowncastToNullable(animal: Animal): void {
var maybeCat = <Cat | null>animal;
if (maybeCat) maybeCat.meow();
}
testDowncastToNullable(new Cat());
function testDowncastFromToNullable(animal: Animal | null): void {
var maybeCat = <Cat | null>animal;
if (maybeCat) maybeCat.meow();
}
testDowncastFromToNullable(new Cat());
__stack_pointer = __heap_base;
__collect();