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