1/*
2 * Copyright (c) 2023-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
16const num: int = 1;
17const param: int = 2;
18
19class A {
20    static invoke(): int {
21        return num;
22    }
23}
24
25class B extends A {
26
27}
28
29class C extends A {
30    static invoke(a: int): int {
31        return a;
32    }
33}
34
35class D extends A {
36    static invoke(cb: ()=>void): int {
37        cb();
38        return num;
39    }
40}
41
42function call_static_invoke_method() {
43    assert A() == num : "expected: " + num + " actual: " + A();
44    assert B() == num : "expected: " + num + " actual: " + B();
45    assert C(param) == param : "expected: " + param + " actual: " + C(param);
46    let d = D() {};
47    assert d == num : "expected: " + num + " actual: " + d;
48}
49
50class Z {
51    z_: int = 0;
52
53    build(): int {
54        return this.z_;
55    }
56
57    static instantiate<T extends Z>(factory: ()=>T): T {
58        let z = factory();
59        z.build();
60        return z;
61    }
62}
63
64class Y {
65    static instantiate<T extends Y>(factory: ()=>T, num: int): T {
66        num++;
67        let y = factory();
68        return y;
69    }
70}
71
72function call_static_instantiate_method() {
73    Z();
74    Y(1);
75}
76
77function main() {
78    call_static_invoke_method();
79    call_static_instantiate_method();
80}
81