• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023-2025 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
16class C {
17    v: int = 0;
18    constructor (v: int) {
19        this.v = v;
20    }
21}
22
23function part0() {
24    let b = false
25    let lam: () => void = () => {
26        assertEQ(b, true)
27        b = false
28    }
29    b = true
30    lam()
31    assertEQ(b, false)
32}
33
34function part1() {
35    let b: byte = 0;
36    let s: short = 0;
37    let i: int = 0;
38    let c: char = 0;
39    let lam: () => void = () => {
40        assertEQ(b, 1)
41        assertEQ(s, 2)
42        assertEQ(i, 3)
43        assertEQ(c, 4)
44        b = 5;
45        s = 6;
46        i = 7;
47        c = 8;
48    };
49    b = 1;
50    s = 2;
51    i = 3;
52    c = 4;
53    lam();
54    assertEQ(b, 5)
55    assertEQ(s, 6)
56    assertEQ(i, 7)
57    assertEQ(c, 8)
58}
59
60function part2() {
61    let l: long = 0;
62    let f: float = Double.toFloat(0.0);
63    let d: double = 0.0;
64    let o = new C(0);
65    let lam: () => void = () => {
66        assertEQ(l, 9)
67        assertEQ(f, 10.0)
68        assertEQ(d, 11.0)
69        assertEQ(o.v, 12)
70        l = 13;
71        f = Double.toFloat(14.0);
72        d = 15.0;
73        o = new C(16);
74    }
75    l = 9;
76    f = Double.toFloat(10.0);
77    d = 11.0;
78    o = new C(12);
79    lam();
80    assertEQ(l, 13)
81    assertEQ(f, 14.0)
82    assertEQ(d, 15.0)
83    assertEQ(o.v, 16)
84}
85
86function main(): void {
87    part0();
88    part1();
89    part2();
90    return;
91}
92