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 */ 15 16let fs: ((p: int) => int)[] 17 18function foo(i: int): ((p: int) => int) { 19 return fs[i] 20} 21 22function main() { 23 fs = [ 24 (p: int): int => p + 1, 25 (p: int): int => p + 2, 26 (p: int): int => p + 3, 27 (p: int): int => p + 4, 28 (p: int): int => p + 5, 29 (p: int): int => p + 6, 30 (p: int): int => p + 7, 31 (p: int): int => p + 8, 32 (p: int): int => p + 9, 33 (p: int): int => p + 0, 34 ] 35 36 // array of promises 37 let ps: Object[] = new Object[10] 38 for (let i = 0; i < 10; i++) { 39 ps[i] = launch foo(i) 40 } 41 42 let cnt = 0 43 for (let i = 9; i >= 0; i--) { 44 cnt += (await ps[i] as Promise<(p: int) => int>)(i) // <- complains on this line 45 } 46 assert cnt == 90 47} 48