• 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 main() {
17  let x1 = (): number | undefined => { return 5; }();
18  let y1: number = !x1 ? 3 : x1;
19  let z1: number = x1 ? x1 : 4;
20  assertEQ(y1, 5.0)
21  assertEQ(z1, 5.0)
22
23  let x2 = (): number | undefined => { return undefined; }();
24  let y2: number = x2 == undefined ? 3 : x2;
25  let z2: number = x2 != undefined ? x2 : 4;
26  assertEQ(y2, 3.0)
27  assertEQ(z2, 4.0)
28
29  let x3 = (): int | undefined => { return 5; }();
30  let y3: int = !x3 ? Double.toInt(3.1) : x3;
31  let z3: int = x3 ? x3 : Double.toInt(4.1);
32  assertEQ(y3, 5)
33  assertEQ(z3, 5)
34
35  let x4 = (): int | undefined => { return undefined; }();
36  let y4: int = x4 == undefined ? Double.toInt(3.1) : x4;
37  let z4: int = x4 != undefined ? x4 : Double.toInt(4.1);
38  assertEQ(y4, 3)
39  assertEQ(z4, 4)
40}
41