1/*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16function force(thunk: ()=>void) {
17    thunk();
18}
19
20function bool2Levels(): void {
21    force(() => {
22        const a0 = true;
23        force(() => {
24            const a1 = a0;
25            assert a0 && a1;
26        });
27    });
28}
29
30function bool4Levels(): void {
31    force(() => {
32        const a0 = true;
33        force(() => {
34            const a1 = a0;
35            force(()=>{
36                const a2 = a1;
37                force(()=>{
38                    const a3 = a2;
39                    assert a0 && a1 && a2 && a3;
40                });
41            });
42        });
43    });
44}
45
46function number4Levels(): void {
47    force(() => {
48        const a0 = 1;
49        force(() => {
50            const a1 = a0;
51            force(()=>{
52                const a2 = a1;
53                force(()=>{
54                    const a3 = a2;
55                    assert 4==a0 + a1 + a2 + a3;
56                });
57            });
58        });
59    });
60}
61
62function array4Levels(): void {
63    force(() => {
64        const a0 = [1,0,0,0];
65        force(() => {
66            const a1 = a0;
67            a1[1]=a0[0];
68            force(()=>{
69                const a2 = a1;
70                a2[2]=a1[1];
71                force(()=>{
72                    const a3 = a2;
73                    a3[3]=a2[2];
74                    assert a0[0]+a0[1]+a0[2]+a0[3]==4;
75                });
76            });
77        });
78    });
79}
80
81function arrayProp4Levels(): void {
82    force(() => {
83        const a0 = [1,0,0,0];
84        force(() => {
85            const a1 = a0;
86            a1[1]=a0[0];
87            force(()=>{
88                const a2 = a1;
89                a2[2]=a1[1];
90                force(()=>{
91                    const a3 = a2;
92                    a3[3]=a2[2];
93                    assert a0.length == 4;
94                    assert a0[0]+a0[1]+a0[2]+a0[3] == 4;
95                });
96            });
97        });
98    });
99}
100
101function paramCapture(): void {
102    const v0 = 1
103    const f0 = (p0:number)=>{
104        const a0 = p0;
105        const f1 = (p1:number)=>{
106            const a1 = a0;
107            const a2 = p1;
108            const a3 = v0;
109            assert a0 + a1 + a2 + a3 == 4;
110        }
111        f1(p0);
112    }
113    f0(v0);
114}
115
116
117function main():void {
118    bool2Levels();
119    bool4Levels();
120    number4Levels();
121    array4Levels();
122    paramCapture();
123}
124