From 8cf1810eb1f7c8d83ce7fbe387030d2ba40dd4df Mon Sep 17 00:00:00 2001 From: wanggengliang Date: Wed, 3 Sep 2025 11:45:59 +0800 Subject: [PATCH] Fix: validate accessor only for function types - Correct type checking in ets2panda/checker/ets/object.cpp - Add new test case ets2panda/test/ast/compiler/ets/class_field_accessor_name_conflict.ets to cover conflict between class field and extension accessor Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICVUAG Signed-off-by: wanggengliang --- ets2panda/checker/ets/object.cpp | 5 +++ .../class_field_accessor_name_conflict.ets | 31 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 ets2panda/test/ast/compiler/ets/class_field_accessor_name_conflict.ets diff --git a/ets2panda/checker/ets/object.cpp b/ets2panda/checker/ets/object.cpp index c9f8409933..2cf7b4e517 100644 --- a/ets2panda/checker/ets/object.cpp +++ b/ets2panda/checker/ets/object.cpp @@ -2261,6 +2261,11 @@ std::vector ETSChecker::ValidateAccessor(ir::MemberExpression * varbinder::Variable *const eAcc, PropertySearchFlags searchFlag) { + if ((eAcc != nullptr && !eAcc->TsType()->IsETSFunctionType()) || + (oAcc != nullptr && !oAcc->TsType()->IsETSFunctionType())) { + memberExpr->SetTsType(GlobalTypeError()); + return {}; + } auto *funcType = eAcc != nullptr ? eAcc->TsType()->AsETSFunctionType() : nullptr; auto *propType = oAcc != nullptr ? oAcc->TsType()->AsETSFunctionType() : nullptr; searchFlag = memberExpr->Parent()->IsUpdateExpression() ? searchFlag | PropertySearchFlags::IS_SETTER : searchFlag; diff --git a/ets2panda/test/ast/compiler/ets/class_field_accessor_name_conflict.ets b/ets2panda/test/ast/compiler/ets/class_field_accessor_name_conflict.ets new file mode 100644 index 0000000000..143c4fd61e --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/class_field_accessor_name_conflict.ets @@ -0,0 +1,31 @@ +/* + * 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. + */ + +class Process { +private + id : number; + constructor(id : number) + { + this.id = id; + } +} + +let p : Process = new Process(1); + +get id(this : Process) : number /* @@ label */{ + return this.id; +} + +/* @@@ label Error TypeError: The extension accessor or extension function 'id' has the same name with field of class Process */ \ No newline at end of file -- Gitee