• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
16type readonly_A = Readonly<A>;
17
18class A {
19    num_mem: Number = 0
20    str_mem: String = ""
21    b_mem: B = new B()
22}
23
24class B {fld: Number = 6}
25
26class C {c_num_mem: Number = 0}
27
28class D  extends C {d_num_mem: Number = 0}
29
30
31function main(): void {
32    let readonly_a: Readonly<A> = {
33        num_mem: 1,
34        str_mem: "readonly_a",
35        b_mem: new B()
36    }
37
38    assert(readonly_a.num_mem == 1)
39    assert(readonly_a.str_mem == "readonly_a")
40    assert(readonly_a.b_mem.fld == 6)
41
42    let readonly_d: Readonly<D> = {
43        c_num_mem: 2,
44        d_num_mem: 3
45    }
46    assert(readonly_d.c_num_mem == 2)
47    assert(readonly_d.d_num_mem == 3)
48
49    let readonly_a2: readonly_A = {
50	num_mem: 4,
51        str_mem: "readonly_a2",
52        b_mem: new B()
53    }
54    assert(readonly_a2.num_mem == 4)
55    assert(readonly_a2.str_mem == "readonly_a2")
56    assert(readonly_a2.b_mem.fld == 6)
57
58}
59