diff --git a/ets2panda/checker/ets/function.cpp b/ets2panda/checker/ets/function.cpp index 0996cf7267c5ff4f8ec71d9f81841d5f429ab3cb..31f6f7a3a5321fac9bd8c05c215f895c26f8fae4 100644 --- a/ets2panda/checker/ets/function.cpp +++ b/ets2panda/checker/ets/function.cpp @@ -1424,8 +1424,12 @@ Signature *ETSChecker::ResolveConstructExpression(ETSObjectType *type, const Are { auto *var = type->GetProperty(compiler::Signatures::CONSTRUCTOR_NAME, PropertySearchFlags::SEARCH_STATIC_METHOD); if (var != nullptr && var->TsType()->IsETSFunctionType()) { - return MatchOrderSignatures(var->TsType()->AsETSFunctionType()->CallSignatures(), nullptr, arguments, pos, - TypeRelationFlag::NONE); + auto sig = MatchOrderSignatures(var->TsType()->AsETSFunctionType()->CallSignatures(), nullptr, arguments, pos, + TypeRelationFlag::NONE); + if (sig == nullptr) { + ThrowOverloadMismatch(type->Name(), arguments, pos, "construct"); + } + return sig; } // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) return ValidateSignatures(type->ConstructSignatures(), nullptr, arguments, pos, "construct"); diff --git a/ets2panda/checker/ets/utilityTypeHandlers.cpp b/ets2panda/checker/ets/utilityTypeHandlers.cpp index 93f6b5eccc737df9ed001d1f9d02975aa04d2d76..22cd11c5f0b9425aa8162f082780511978759540 100644 --- a/ets2panda/checker/ets/utilityTypeHandlers.cpp +++ b/ets2panda/checker/ets/utilityTypeHandlers.cpp @@ -503,8 +503,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; } 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 diff --git a/ets2panda/test/ast/compiler/ets/overload_for_named_constructor.ets b/ets2panda/test/ast/compiler/ets/overload_for_named_constructor.ets new file mode 100644 index 0000000000000000000000000000000000000000..0575959c2f8e34bbe7c7838f50b08d8d0ef4c794 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/overload_for_named_constructor.ets @@ -0,0 +1,26 @@ +/** + * 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 A{ + overload constructor {foo, bar}; + constructor foo(a:string, b?:string){} + constructor bar(a:number, b?:number){} +} + +function main(){ + new A() +} + +/* @@? 23:5 Error TypeError: No matching construct signature for A() */ \ No newline at end of file