• 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
16struct cls {
17  member_cls: cls | null;
18  member_int: int;
19
20  constructor(arg_cls: cls | null, arg_int: int) {
21    this.member_cls = arg_cls;
22    this.member_int = arg_int;
23  }
24}
25
26struct cls2 {
27  member_cls: cls | null = null;
28  member_int: int;
29}
30
31function main(): void {
32    // TODO: catch NullPointerError if exception handling is implemented
33    // let x : cls;
34    // x.member_cls;
35
36    let y : cls = new cls(null, 2);
37    assertEQ(y.member_cls, null)
38    assertEQ(y.member_int, 2)
39
40    // TODO: catch NullPointerError if exception handling is implemented
41    // y = null;
42    // y.member_cls;
43
44    let z : cls = new cls(y, 4);
45    assertNE(z.member_cls, null)
46    assertEQ(z.member_int, 4)
47
48    let u : cls2 = new cls2();
49    assertEQ(u.member_cls, null)
50    assertEQ(u.member_int, 0)
51
52    return;
53}
54