• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024-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
16function foo(x: int): string
17{
18  let rc: string|undefined = "default";
19
20  label1: switch(x) {
21    case 0:
22       rc = "case 0";
23    case 1: {
24       let rc1: string|undefined = ():string => {return "case 1";}();
25       label2: switch(rc) {
26          case "default":
27             rc = undefined;
28             break label2;
29          default:
30             break label1;
31       }
32       rc = rc1;
33       break;
34    }
35    case 2:
36       rc = undefined;
37       let rc2: string|null = ():string => {return "case 2";}();
38       return rc2;
39    case 3:
40       rc = "case 3";
41       break;
42    case 4:
43       rc = undefined;
44    default:
45       return rc != null ? rc :"case 4"
46    case 5:
47       rc = "case 5";
48  }
49
50  return rc;
51}
52
53
54function main(): void {
55  assertEQ(foo(0), "case 0")
56  assertEQ(foo(1), "case 1")
57  assertEQ(foo(2), "case 2")
58  assertEQ(foo(3), "case 3")
59  assertEQ(foo(4), "case 4")
60  assertEQ(foo(5), "case 5")
61  assertEQ(foo(7), "default")
62}
63