1/* 2 * Copyright (c) 2022-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 16namespace testing { 17 export class Array<T> { 18 $_get(index: number): Array<T> {return this;} 19 $_set(index: number, value: Array<T>) {} 20 } 21 export class ReadonlyArray<T> { 22 $_get(index: number): ReadonlyArray<T> {return this;} 23 $_set(index: number, value: ReadonlyArray<T>) {} 24 } 25 export class ConcatArray<T> { 26 $_get(index: number): ConcatArray<T> {return this;} 27 $_set(index: number, value: ConcatArray<T>) {} 28 } 29 export class ArrayLike<T> { 30 $_get(index: number): ArrayLike<T> {return this;} 31 $_set(index: number, value: ArrayLike<T>) {} 32 } 33} 34 35namespace testing2 { 36 export class Array<T> {[x: number]: any} 37 export class ReadonlyArray<T> {[x: number]: any} 38 export class ConcatArray<T> {[x: number]: any} 39 export class ArrayLike<T> {[x: number]: any} 40} 41 42// no error 43function retA() { 44 let a: Array<number> = [1,2,3]; 45 let b: ReadonlyArray<number> = [1,2,3]; 46 let c: ConcatArray<number> = [1,2,3]; 47 let d: ArrayLike<number> = [1,2,3]; 48 // no error 49 return a[0] + b[0] + c[0] + d[0]; 50} 51 52// error 53function retB() { 54 let a = new testing.Array<number>(); 55 let b = new testing.ReadonlyArray<number>(); 56 let c = new testing.ConcatArray<number>(); 57 let d = new testing.ArrayLike<number>(); 58 // no error 59 return a[0] + b[0] + c[0] + d[0]; 60} 61 62// error 63function retC() { 64 let a = new testing2.Array<number>(); 65 let b = new testing2.ReadonlyArray<number>(); 66 let c = new testing2.ConcatArray<number>(); 67 let d = new testing2.ArrayLike<number>(); 68 // 4 error 69 return a[0] + b[0] + c[0] + d[0]; 70} 71