• 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
16class A {
17    constructor(tag: string) { this.tag = tag }
18    toString() { return this.tag }
19    tag: string
20}
21class B extends A {
22    constructor(tag: string) {
23        super(tag)
24    }
25}
26
27function test(f: Function, action: (f: Function) => Any, v: Any) {
28    assertEQ(action(f), v)
29}
30
31function main() {
32    test((a: A) => "" + a,
33        (f) => f.unsafeCall(new B("tag")),
34        "tag"
35    )
36    test((a: string, b: string) => a + b,
37        (f) => f.unsafeCall("a", "b", "c"),
38        "ab"
39    )
40    // NOTE(vpukhov): optional arity is not preserved
41    // test((a: string, b?: string) => a + b,
42    //     (f) => f.unsafeCall("a"),
43    //     "aundefined"
44    // )
45    test((...a: string[]) => a[0] + a[1],
46        (f) => f.unsafeCall("a", "b"),
47        "ab"
48    )
49    test((...a: A[]) => "" + a[0] + a[1],
50        (f) => f.unsafeCall(new A("taga"), new B("tagb")),
51        "tagatagb"
52    )
53    test((p1: A, ...a: A[]) => "" + p1,
54        (f) => f.unsafeCall(new A("1")),
55        "1"
56    )
57    test((p1: A, ...a: A[]) => "" + p1 + a[0] + a[1],
58        (f) => f.unsafeCall(new A("1"), new A("2"), new A("3")),
59        "123"
60    )
61}
62