• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
16class A { foo() {}}
17class B extends A { bar() {}}
18
19type num_str_str_type = [number, string, string];
20type num_str_str_with_spread = [num_str_str_type, ...number[]];
21
22function foo(a0: number, args: [...number[]]): number {
23    return 2;
24}
25
26
27function main(): void {
28    const tup_arr_1: num_str_str_type[] = [
29        [0, "a", "d"],
30        [1, "b", "e"],
31        [2, "c", "f"],
32    ];
33
34    const tup_arr_2: num_str_str_with_spread[] = [
35        [tup_arr_1[0], 250],
36        [tup_arr_1[1], 250, 260],
37        [tup_arr_1[0], 300, 300, 300],
38    ];
39
40    const a_var = tup_arr_2[0][1] + tup_arr_2[1][1] + tup_arr_2[2][1];
41    const b_var = tup_arr_2[1][2] + tup_arr_2[2][2];
42    const c_var = tup_arr_2[2][2];
43
44    foo(tup_arr_1[0][0], [tup_arr_2[0][1]]);
45    foo(tup_arr_1[1][0], [tup_arr_2[1][1], tup_arr_2[1][2]]);
46
47    let arr: Object[] = [1,2,3,4,5];
48    let double_ref_tup: [Number, Number, Number] = [6 as double, 7 as double, 8 as double];
49    let a_arr: A[];
50    let b_tup: [B, B] = [new B(), new B()];
51    let b_arr: B[] = [new B(), new B()];
52
53    arr = double_ref_tup;
54    a_arr = b_tup;
55    b_arr = b_tup;
56
57    let spread_tup: [Number, ...Number[]] = [6 as double,7 as double,8 as double, 9 as double, 10 as double];
58    let num_ref_arr: Number[] = [1 as double,2 as double,3 as double,4 as double,5 as double];
59
60    spread_tup = num_ref_arr;
61
62    let num_tup: [number, number] = [11,2];
63    let num_prim_arr: number[] = [3,4];
64
65    num_prim_arr = num_tup;
66
67    let d_var: [number, string] = [1, "A"];
68    let e_var: [number, string, boolean] = [1, "A", true];
69    let f_var: [number, string, boolean, number, string];
70    f_var = [1, "A", true, 20, "B"];
71
72    let g_var: [number, string][];
73    g_var = [[1, "A"], [2, "B"], [3, "C"]];
74
75    // #15570 - test ArrayExpr assignability with individual element types
76    // let h_var: [number, int, string, boolean, Object] = [1, 2, "asd", false, new Object()];
77    // let i_var: float = h_var[1];
78    // let j_var: [int, number, string, boolean, Object] = [6, 7, "abc", true, 666];
79    // NOTE: Bug in op_assignment lowering (removes const from property)
80    // j_var[0] += new Short(2 as short);
81
82    let empty: [] = [];
83}
84