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
16class 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
26class 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    assert (y.member_cls == null && y.member_int == 2)
38
39    // TODO: catch NullPointerError if exception handling is implemented
40    // y = null;
41    // y.member_cls;
42
43    let z : cls = new cls(y, 4);
44    assert (z.member_cls != null && z.member_int == 4)
45
46    let u : cls2 = new cls2();
47    assert (u.member_cls == null && u.member_int == 0)
48
49    return;
50}
51