diff --git a/ets2panda/checker/ets/object.cpp b/ets2panda/checker/ets/object.cpp index 9c9cd7bd4e1f5db01d351cb58a1b9ab01f63e05f..9c183122991728f4162dea21ff2430f89d668340 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 0000000000000000000000000000000000000000..2bca2ab41562fb323d843d96c7a5cb0300f0f473 --- /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; +}