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 */
15import {OhosInterface} from './oh_modules/ohos_lib'
16// #14071
17class A {
18  v: string = '';
19}
20function SetProperty<T extends Object>(oldObj: T, str: string, obj: Object): void {
21  oldObj[str] = obj; // Should report error
22}
23function GetProperty<T extends Object, U>(oldObj: T, str: string): U {
24  return oldObj[str]; // Should report error
25}
26function test() {
27  let a: A = { v: 'abc' };
28  SetProperty(a, 'u', 'def');
29  return GetProperty<A, string>(a, 'v') + GetProperty<A, string>(a, 'u');
30}
31
32let ar1 = [1, 2, 3, 4];
33let ar2 = [1, '2', 3, 4];
34let ar3: number[] = [];
35
36ar1[2];
37ar2[2];
38ar3[2];
39
40const r0 = [1, 2, 3][1];
41let r1 = [1, 2, 3, 4][0]
42let r2 = [1, '2', 3, 4][0]
43
44function fobject1(o: object) {
45  o['j']
46}
47
48function fobject2(o: Object) {
49  o['k']
50}
51
52let array1 = [0,1]
53let array2 = [1,2,3,4,5]
54let array3: number[] = [1,2,3,4,5]
55let array4: Array<number> = [1,2,3,4,5]
56let array5 = new Array(10)
57let array6 = new Int8Array(10)
58let array7 = new Uint8Array(10)
59let array8 = new Uint8ClampedArray(10)
60let array9 = new Int16Array(10)
61let array10 = new Uint16Array(10)
62let array11 = new Int32Array(10)
63let array12 = new Uint32Array(10)
64let array13 = new Float32Array(10)
65let array14 = new Float64Array(10)
66let array15 = new BigInt64Array(10)
67let array16 = new BigUint64Array(10)
68
69array1[0];
70array2[0];
71array3[0];
72array4[0];
73array5[0];
74array6[0];
75array7[0];
76array8[0];
77array9[0];
78array10[0];
79array11[0];
80array12[0];
81array13[0];
82array14[0];
83array15[0];
84array16[0];
85
86function fff1(r: Record<string, number>) {
87    r['bob']
88}
89
90enum CCCCCCCCC {
91  KATE,
92  BOB,
93  ROB,
94}
95
96CCCCCCCCC['KATE']
97CCCCCCCCC['BOB']
98CCCCCCCCC['ROB']
99
100CCCCCCCCC[CCCCCCCCC.KATE]
101CCCCCCCCC[CCCCCCCCC.BOB]
102CCCCCCCCC[CCCCCCCCC.ROB]
103
104let arr32 = new Float32Array([1,2,3])
105
106let iter_arr32 = arr32[Symbol.iterator]()
107let tmp_arr32 = iter_arr32.next().value;
108while (!!tmp_arr32) {
109  console.log(tmp_arr32[0])
110
111  tmp_arr32 = iter_arr32.next().value
112}
113
114let arr = new Array<string>()
115arr = ['a','f','g']
116let iter_arr = arr[Symbol.iterator]()
117let tmp_arr = iter_arr.next().value;
118while (!!tmp_arr) {
119  console.log(tmp_arr[0])
120  tmp_arr = iter_arr.next().value
121}
122
123// #14415
124class ArrayContainer {
125  numbers: number[] = [];
126}
127class NullableArray {
128  container: ArrayContainer | null = null;
129
130  print() {
131    console.log(this.container?.numbers[0]);
132  }
133}
134
135let str1 = 'sssss'
136let str2 = "aaaaa"
137let str3 = `sssss`
138let str4 = new String('sssss')
139let str5 = str1
140let str6 = str2
141
142str1[1]
143str2[1]
144str3[1]
145str4[1]
146str5[1]
147str6[1]
148
149class AString extends String {}
150let str7 = new AString('dwdd')
151str7[1]
152
153type IndexableUnion = string[] | (number | string)[] | Uint8Array;
154type NonIndexableUnion = string[] | number[] | Uint8Array | number;
155
156function indexUnion(iu: IndexableUnion, niu: NonIndexableUnion) {
157  iu[0];
158  niu[0];
159}
160
161function testLibraryUnnamedType(a: OhosInterface) {
162  a['kek'];
163}
164
165class MMap<T, U> extends Map<T, U> {}
166
167let mmap1 = new Map<number, string>();
168let mmap2 = new Map<string, number>();
169let mmap3 = new MMap<string, string>();
170
171mmap1[1];
172mmap2['222'];
173mmap3["kkr"];
174