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