diff --git a/ets2panda/checker/ets/object.cpp b/ets2panda/checker/ets/object.cpp index c9f84099333ac32174502e1337303c2a71e50e5d..2cf7b4e51724bf0cdb0c5f3ad4697600fcdab7d5 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 0000000000000000000000000000000000000000..143c4fd61e4d30839729c326f29eee08bfb433cb --- /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