diff --git a/ets2panda/checker/ets/utilityTypeHandlers.cpp b/ets2panda/checker/ets/utilityTypeHandlers.cpp index c2671c47b176ee86715881bd233f866efe077441..3009f298cd2d0ddcd438608ad7f8a4fbbb57415d 100644 --- a/ets2panda/checker/ets/utilityTypeHandlers.cpp +++ b/ets2panda/checker/ets/utilityTypeHandlers.cpp @@ -491,8 +491,12 @@ void ETSChecker::CreatePartialClassDeclaration(ir::ClassDefinition *const newCla prop->AsMethodDefinition()->Function()->IsSetter())) { auto *method = prop->AsMethodDefinition(); ES2PANDA_ASSERT(method->Id() != nullptr); + auto isBrokenSetter = method->Function()->IsSetter() && method->Function()->Params().size() != 1; + auto isBrokenGetter = method->Function()->IsGetter() && !method->Function()->Params().empty(); if (newClassDefinition->Scope()->FindLocal(method->Id()->Name(), - varbinder::ResolveBindingOptions::VARIABLES) != nullptr) { + varbinder::ResolveBindingOptions::VARIABLES) != nullptr || + isBrokenSetter || isBrokenGetter) { + ES2PANDA_ASSERT(IsAnyError()); continue; } // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) diff --git a/ets2panda/test/ast/compiler/ets/broken_setter.ets b/ets2panda/test/ast/compiler/ets/broken_setter.ets new file mode 100644 index 0000000000000000000000000000000000000000..9330afc1737c32002ffde4b3079d3823fd1548f3 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/broken_setter.ets @@ -0,0 +1,32 @@ +/* + * 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. + */ + +let i = 0 + +class A{ + set p(){ + i+=1 + } + + get p():number { + return this.p + } +} + +function foo(p:Partial){} + +/* @@? 23:5 Error SyntaxError: Setter must have exactly one formal parameter. */ +/* @@? 23:5 Error TypeError: Function p is already declared. */ +/* @@? 24:21 Warning Warning: Reading the value of the property inside its getter may lead to an endless loop. */ \ No newline at end of file