• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 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(arg: Object) : int {
17  return 1;
18}
19
20function fooB(arg: Object|undefined) : int {
21  return 2;
22}
23
24function fooC(arg: Object|undefined|null) : int {
25  return 3;
26}
27
28function fooD(arg: undefined|null|int) : int {
29  return 4;
30}
31
32function fooE(arg: undefined|null|boolean) : int {
33  return 5;
34}
35
36function fooF(arg: undefined|null|string) : int {
37  return 6;
38}
39
40function fooG(arg: undefined|null|string) : int {
41  return 7;
42}
43
44
45function main(): void {
46  let a: Object|undefined = new Object();
47  let b: Object|undefined = undefined;
48  let c: Object|undefined|null = null;
49  let d: int|undefined|null = 0;
50  let e: boolean|undefined|null = false;
51  let f: string|undefined|null = "";
52  let g: string|undefined|null = "Hello World!";
53
54  assertEQ( foo(a), 1 );
55  assertEQ( foo(a!), 1 );
56  assertEQ( fooB(b), 2 );
57  assertEQ( fooC(c), 3 );
58  assertEQ( fooD(d!), 4 );
59  assertEQ( fooE(e!), 5 );
60  assertEQ( fooF(f!), 6 );
61  assertEQ( fooG(g!), 7 );
62}