From 802c437808891d0f7dc6d2396ef8ae83b4b923b7 Mon Sep 17 00:00:00 2001 From: Csaba Osztrogonac Date: Thu, 21 Dec 2023 04:29:52 +0100 Subject: [PATCH] [ArkTS] Fix IsETSFunctionType() assertion for lambda fields Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I8Q7HZ Fixes the internal issue #14719. Change-Id: I95c5305316f238f342f1f021eb782fedbf59cec4 Signed-off-by: Csaba Osztrogonac --- ets2panda/checker/ets/object.cpp | 4 +++ .../test/runtime/ets/lambda-class-field.ets | 26 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 ets2panda/test/runtime/ets/lambda-class-field.ets diff --git a/ets2panda/checker/ets/object.cpp b/ets2panda/checker/ets/object.cpp index 9c9cd7bd4e..9c18312299 100644 --- a/ets2panda/checker/ets/object.cpp +++ b/ets2panda/checker/ets/object.cpp @@ -850,6 +850,10 @@ void ETSChecker::CheckConstFieldInitialized(const ETSObjectType *class_type, var { const bool class_var_static = class_var->Declaration()->Node()->AsClassProperty()->IsStatic(); for (const auto &prop : class_type->Methods()) { + if (!prop->TsType()->IsETSFunctionType()) { + continue; + } + const auto &call_sigs = prop->TsType()->AsETSFunctionType()->CallSignatures(); for (const auto *signature : call_sigs) { if ((signature->Function()->IsConstructor() && !class_var_static) || diff --git a/ets2panda/test/runtime/ets/lambda-class-field.ets b/ets2panda/test/runtime/ets/lambda-class-field.ets new file mode 100644 index 0000000000..2bca2ab415 --- /dev/null +++ b/ets2panda/test/runtime/ets/lambda-class-field.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023 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. + */ + +class cls { + lambda_field: (() => int) | undefined; + readonly num: int; // don't remove it, it is necessary to trigger an issue with the lambda +} + +function main(): void { + let c = new cls(); + c.lambda_field = () => 42; + assert c.lambda_field() == 42; + assert c.num == 0; +} -- Gitee