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