-
-
Notifications
You must be signed in to change notification settings - Fork 670
/
Copy pathunsafe.ts
77 lines (52 loc) · 1.04 KB
/
unsafe.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Function
@unsafe function f1(): void {}
f1();
// Inline function
@unsafe @inline function f2(): void {}
f2();
// === Class members ===
class Foo {
@unsafe constructor() {}
@unsafe static foo: i32 = 0;
@unsafe static bar(): void {}
@unsafe foo: i32 = 0;
@unsafe bar(): void {}
@unsafe static get baz(): i32 { return 0; }
@unsafe static set baz(i: i32) { }
@unsafe get baz(): i32 { return 0; }
@unsafe set baz(i: i32) { }
}
// Constructor
var foo = new Foo();
// Constructor via super
class Bar extends Foo {
constructor() { super(); }
}
var bar = new Bar();
// Constructor via instantiate
var foo3 = instantiate<Foo>();
// Static method
Foo.bar();
// Instance method
foo.bar();
// Static field
var n1 = Foo.foo;
Foo.foo = 1;
Foo.foo++;
Foo.foo += 1;
// Instance field
var n2 = foo.foo;
foo.foo = 1;
foo.foo++;
foo.foo += 1;
// Static property
var n3 = Foo.baz;
Foo.baz = 1;
Foo.baz++;
Foo.baz += 1;
// Instance property
var n4 = foo.baz;
foo.baz = 1;
foo.baz++;
foo.baz += 1;
ERROR("EOF"); // mark end and ensure fail