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'use static' 16 17const arr: int[] = [1.0, 2.0, 3.0, 4.0]; 18 19for (let i: number = 0.0; i < arr.length; i++) { 20 arr[i as int]; //legal 21} 22 23for (let i: number = 0.0; i < 100.0; i++) { 24 console.log(i); //legal 25} 26 27const arr2: int[] = [1.0, 2.0, 3.0, 4.0]; 28for (let i: number = 0.0; i < 100.0; i++) { 29 arr2[10] //should report 30} 31 32const arr3: int[] = [1.0, 2.0, 3.0, 4.0]; 33for (let i: number = 0.0; i < arr3.length; i++) { 34 arr3[10] //should report 35} 36 37const arr4: int[] = [1.0, 2.0, 3.0, 4.0]; 38let x: int = 3.0; 39for (let i: number = 0.0; i < arr4.length; i++) { 40 arr4[x]; //should report 41} 42 43const arr5: int[] = [1.0, 2.0, 3.0, 4.0]; 44for (let i: number = 0.0; i < 10.0; i++) { 45 arr5[i as int]; //should report 46} 47 48 49const arr6: int[] = [1.0, 2.0, 3.0, 4.0]; 50if (arr6.length > 10.0) { 51 arr6[10] 52} 53 54const arr7: int[] = [1.0, 2.0, 3.0, 4.0]; 55if (arr7.length > 10.0) { 56 return; 57} 58 59arr7[10] 60 61const arr8: int[] = [1.0, 2.0, 3.0, 4.0]; 62const index: int = 9.0; 63if (arr8.length > 10.0 && index > 0.0) { 64 return; 65} 66 67arr8[index]; 68 69const arr9: int[] = [1.0, 2.0, 3.0, 4.0]; 70if (arr9.length > 10.0 && index > 0.0) { 71 arr9[index]; 72} 73 74const arr10: int[] = [1.0, 2.0, 3.0, 4.0]; 75if (index > 0.0) { 76 arr10[index]; 77} 78 79const arr10: int[] = [1.0, 2.0, 3.0, 4.0]; 80let newIndex: number = 10.0; 81if (arr10.length > newIndex) { 82 return; 83} 84 85newIndex = 22.0; 86 87arr10[newIndex as int]; 88 89let arr: number[] = [0.0, 1.0, 2.0, 3.0, 4.0, 5.0] 90for(let i: number = 0.0; i < arr.length; i++) { 91arr[i as int] = arr[i as int] + 1.0; 92} 93for(let i: number = 0.0; i < arr.length; i++) { 94i = 10.0; 95arr[i as int] = arr[i as int] + 1.0; 96} 97 98let arr: number[] = [0.0, 1.0, 2.0, 3.0, 4.0, 5.0] 99let idx: number = 2.0; 100if(idx > 0.0 && idx < arr.length) { 101arr[idx as int] = arr[idx as int] + 1.0; 102} 103if(idx > 0.0 && idx < arr.length) { 104idx = 10.0; 105arr[idx as int] = arr[idx as int] + 1.0; 106} 107 108let arr: number[] = [0.0, 1.0, 2.0, 3.0, 4.0, 5.0] 109let idx: number = 0.0; 110while(idx > 0.0 && idx < arr.length) { 111arr[idx as int] = arr[idx as int] + 1.0; 112idx++; 113idx = 10.0; 114} 115while(idx > 0.0 && idx < arr.length) { 116idx = 10.0; 117arr[idx as int] = arr[idx as int] + 1.0; 118} 119 120let arr: number[] = [0.0, 1.0, 2.0, 3.0, 4.0, 5.0] 121let idx: number = 0.0; 122arr[idx as int]; 123arr[10]; 124if (arr.length > 10.0) { 125arr[10] = 10.0; 126} 127 128function foo():int{ 129return 1.0; 130} 131 132arr[(44/3) as int]; 133arr[foo()]; 134arr[()=>{return 1}]; 135if(arr.length > foo()) { 136arr[foo()]; 137} 138if(arr.length > 44.0/3.0) { 139arr[(4*4/3) as int]; 140} 141 142let arr1:number[] = [1.0, 1.5,45.0,2.0] 143 144function foo(i:number):number{ 145 return i; 146} 147 148arr1[3*5] = 23.0; 149arr1[parseInt("16") as int] = 23.0; 150arr1[foo(16) as int] = 23.0 151 152let arr1:number[] = [1.0, 1.5,45.0,2.0] 153 154arr1[Number.MAX_VALUE as int] = 23.0; 155arr1[Number.MAX_SAFE_INTEGER as int] = 23.0; 156 157let arr1:number[] = [1.0, 1.5,45.0,2.0] 158function foo(i:number):number{ 159 return i; 160} 161arr1[(24)] = 23.0; 162arr1[+24] = 23.0; 163enum TE{ 164 AA = 12.0 165} 166arr1[TE.AA] = 12.0; 167 168let a: string[] = []; 169let b: Array<string> = new Array<string>(a.length); 170for (let i: number = 0.0; i < a.length; i++) { 171 b[i as int]; 172}