From f10b792d1f8e8765f200032ed0b4958d63d7188c Mon Sep 17 00:00:00 2001 From: Boglarka Haag Date: Mon, 30 Jun 2025 13:34:50 +0200 Subject: [PATCH] Fix crash on callbacks Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICIXCV Reason: Fixed crash when generic callback function was called with less params then expected Description: Modified EnchanceSignatureSubstitution Fixes internal issue: #26930 Signed-off-by: Haag Boglarka --- .../checker/types/ets/etsFunctionType.cpp | 2 +- .../ast/compiler/ets/generic_callback.ets | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 ets2panda/test/ast/compiler/ets/generic_callback.ets diff --git a/ets2panda/checker/types/ets/etsFunctionType.cpp b/ets2panda/checker/types/ets/etsFunctionType.cpp index 7c757922b82..23a5f92808d 100644 --- a/ets2panda/checker/types/ets/etsFunctionType.cpp +++ b/ets2panda/checker/types/ets/etsFunctionType.cpp @@ -168,7 +168,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->ArgCount(); ix++) { if (!enhance(sub->GetSignatureInfo()->params[ix]->TsType(), super->GetSignatureInfo()->params[ix]->TsType())) { return nullptr; } diff --git a/ets2panda/test/ast/compiler/ets/generic_callback.ets b/ets2panda/test/ast/compiler/ets/generic_callback.ets new file mode 100644 index 00000000000..92c4b7ad7e8 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/generic_callback.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 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; +} +let x = [1, 2, 3].map(identity)[0]; + +/* @@? 19:9 Error TypeError: No matching call signature for map((a: A) => A) */ +/* @@? 19:9 Error TypeError: Indexed access is not supported for such expression type. */ +/* @@? 19:9 Error TypeError: No matching call signature for map((a: A) => A) */ +/* @@? 19:9 Error TypeError: Indexed access is not supported for such expression type. */ +/* @@? 19:23 Error TypeError: Type '(a: A) => A' is not compatible with type '(value: Int, index: Double, array: Array) => A' at index 1 */ +/* @@? 19:23 Error TypeError: Type '(a: A) => A' is not compatible with type '(value: Int, index: Double, array: ReadonlyArray) => A' at index 1 */ +/* @@? 19:23 Error TypeError: Type '(a: A) => A' is not compatible with type '(value: Int, index: Double, array: Array) => A' at index 1 */ +/* @@? 19:23 Error TypeError: Type '(a: A) => A' is not compatible with type '(value: Int, index: Double, array: ReadonlyArray) => A' at index 1 */ -- Gitee