diff --git a/ets2panda/checker/types/ets/etsFunctionType.cpp b/ets2panda/checker/types/ets/etsFunctionType.cpp index 0ec3b4ecaca3259907143dc8f1e7358d05407ff4..0fc7d18f4c9d380678e61884606c1b1868746fb3 100644 --- a/ets2panda/checker/types/ets/etsFunctionType.cpp +++ b/ets2panda/checker/types/ets/etsFunctionType.cpp @@ -184,7 +184,7 @@ static Signature *EnhanceSignatureSubstitution(TypeRelation *relation, Signature auto const enhance = [checker, sub, &substitution](Type *param, Type *arg) { return checker->EnhanceSubstitutionForType(sub->GetSignatureInfo()->typeParams, param, arg, &substitution); }; - for (size_t ix = 0; ix < super->MinArgCount(); ix++) { + for (size_t ix = 0; ix < sub->MinArgCount(); ix++) { if (!enhance(sub->GetSignatureInfo()->params[ix]->TsType(), super->GetSignatureInfo()->params[ix]->TsType())) { return nullptr; } diff --git a/ets2panda/test/ast/compiler/ets/lambda_parameter.ets b/ets2panda/test/ast/compiler/ets/lambda_parameter.ets new file mode 100644 index 0000000000000000000000000000000000000000..a32fd95c12b937d61e401be5b89ad4894fc42992 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/lambda_parameter.ets @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2021-2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function identity(a: A): A { + return a; +} + +class MyArray { + map(callbackfn: (value: T, index: number) => void) { } +} + +function main() { + let x = /* @@ label1 */[1, 2, 3].map(/* @@ label2 */identity)[0]; + + let a = new MyArray(); + a.map(/* @@ label3 */(a: A): A => {return a }); + /* @@ label4 */a.map(/* @@ label5 */identity); +} + +/* @@@ label1 Error TypeError: No matching call signature for map((a: A) => A) */ +/* @@@ label1 Error TypeError: Indexed access is not supported for such expression type. */ +/* @@@ label2 Error TypeError: Type '(a: A) => A' is not compatible with type '(value: Int, index: Double, array: Array) => A' at index 1 */ +/* @@@ label2 Error TypeError: Type '(a: A) => A' is not compatible with type '(value: Int, index: Double, array: ReadonlyArray) => A' at index 1 */ +/* @@@ label3 Error TypeError: Type '(a: A) => A' is not compatible with type '(value: Int, index: Double) => void' at index 1 */ +/* @@@ label4 Error TypeError: No matching call signature for map((a: A) => A) */ +/* @@@ label5 Error TypeError: Type '(a: A) => A' is not compatible with type '(value: Int, index: Double) => void' at index 1 */