- Notifications
You must be signed in to change notification settings - Fork 670
/
Copy pathassignment-chain.ts
47 lines (44 loc) · 928 Bytes
/
assignment-chain.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
classA{
x: i64=0;
y: i64=0;
}
exportfunctionnormal_assignment_chain(): void{
letx=newA();
letcnt=0;
x.x=x.y=cnt++;
assert(cnt==1);// `cnt++` should be executed only once
}
normal_assignment_chain();
classB{
_setter_cnt: i32=0;
_getter_cnt: i32=0;
_y: f64=0.0;
sety(z: f64){
this._setter_cnt+=1;
this._y=z;
}
gety(): f64{
this._getter_cnt+=1;
returnthis._y;
}
}
exportfunctionsetter_assignment_chain(): void{
letx=newB();
x.y=x.y=1;
assert(x._setter_cnt==2);
assert(x._getter_cnt==0);// should not use getter method
}
setter_assignment_chain();
classC{
static_setter_cnt: i32=0;
static_y: f64=0.0;
staticsety(z: f64){
C._setter_cnt+=1;
C._y=z;
}
}
exportfunctionstatic_setter_assignment_chain(): void{
C.y=C.y=1;
assert(C._setter_cnt==2);
}
static_setter_assignment_chain();