1/*
2 * Copyright (c) 2023-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
16let q: int = 1;  // variable in top-level scope
17let s = "abc"
18
19switch (q) {
20  case 1: {
21    q += 2; 
22    break;
23  }
24  case 2: {
25    assert(false)
26    break;
27  }
28}
29
30class TestException extends Exception {
31}
32
33assert(q == 3)
34assert(s == "abc")
35
36try {
37  s += "cba";
38  q += 5;
39  throw new TestException();
40}
41catch (e: TestException) {
42}
43catch (e) {
44  assert(false)
45}
46
47assert(q == 8)
48assert(s == "abccba")
49
50function main(): void {
51  ETSGLOBAL.q = 1;
52  let q: int;  // function main scope, top-level q is shadowed
53  q = q + 30;
54  assert(q == 30)
55  assert(ETSGLOBAL.q == 1)
56
57  assert(s == "abccba")
58  s = "def";
59  assert(s == "def")
60
61  _$init$_();
62   
63  assert(s == "abccba")
64  assert(q == 30)
65  assert(ETSGLOBAL.q == 8)
66}
67