diff --git a/ets2panda/checker/types/ets/etsObjectType.cpp b/ets2panda/checker/types/ets/etsObjectType.cpp index b07059d2748deb243640fd252d3c9c0d71bd93ff..479bce100a410832671c9288a9be12525d80e382 100644 --- a/ets2panda/checker/types/ets/etsObjectType.cpp +++ b/ets2panda/checker/types/ets/etsObjectType.cpp @@ -235,16 +235,14 @@ varbinder::LocalVariable *ETSObjectType::CollectSignaturesForSyntheticType(std:: if ((flags & PropertySearchFlags::SEARCH_STATIC_METHOD) != 0) { if (auto *found = GetOwnProperty(name); - found != nullptr && !found->TsType()->IsTypeError()) { - ES2PANDA_ASSERT(found->TsType()->IsETSFunctionType()); + found != nullptr && found->TsType()->IsETSFunctionType()) { AddSignature(signatures, flags, checker, found); } } if ((flags & PropertySearchFlags::SEARCH_INSTANCE_METHOD) != 0) { if (auto *found = GetOwnProperty(name); - found != nullptr && !found->TsType()->IsTypeError()) { - ES2PANDA_ASSERT(found->TsType()->IsETSFunctionType()); + found != nullptr && found->TsType()->IsETSFunctionType()) { AddSignature(signatures, flags, checker, found); } } @@ -261,8 +259,7 @@ varbinder::LocalVariable *ETSObjectType::CollectSignaturesForSyntheticType(std:: !this->IsPartial()) { // NOTE: issue 24548 if (auto *found = interface->GetProperty(name, flags | PropertySearchFlags::DISALLOW_SYNTHETIC_METHOD_CREATION); - found != nullptr && !found->TsType()->IsTypeError()) { - ES2PANDA_ASSERT(found->TsType()->IsETSFunctionType()); + found != nullptr && found->TsType()->IsETSFunctionType()) { AddSignature(signatures, flags, checker, found); } } diff --git a/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp b/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp index 4d386ae30be6f0a5da0bef32d1780020182a0182..4e0606e170ebc225fb2eb3bafaf2c35b547c6b80 100644 --- a/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp +++ b/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp @@ -1119,6 +1119,7 @@ void InitScopesPhaseETS::VisitTSTypeParameter(ir::TSTypeParameter *typeParam) var->AddFlag(varbinder::VariableFlags::TYPE_PARAMETER); decl->BindNode(typeParam); CallNode(typeParam->Annotations()); + CallNode(typeParam->DefaultType()); } void InitScopesPhaseETS::VisitTSInterfaceDeclaration(ir::TSInterfaceDeclaration *interfaceDecl) diff --git a/ets2panda/test/ast/compiler/ets/bad_call_setter.ets b/ets2panda/test/ast/compiler/ets/bad_call_setter.ets new file mode 100644 index 0000000000000000000000000000000000000000..2bfd2c9474fc77f2e8e5bb70fec88ac0dd2ba02f --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/bad_call_setter.ets @@ -0,0 +1,35 @@ +/* + * 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. + */ + +interface I { + set text(s: string) +} + +class B implements I { + text: string = "" + s : string + this.text = s; +} + +function main() { + let ins: I = new B(); + ins.text = "He"; +} + +/* @@? 23:5 Error SyntaxError: Unexpected token 'this'. */ +/* @@? 23:9 Error SyntaxError: Unexpected token '.'. */ +/* @@? 23:10 Error TypeError: Variable 'text' has already been declared. */ +/* @@? 23:10 Error TypeError: Property 'text' must be accessed through 'this' */ +/* @@? 23:17 Error TypeError: Property 's' must be accessed through 'this' */ diff --git a/ets2panda/test/ast/compiler/ets/try_catch_already_declared.ets b/ets2panda/test/ast/compiler/ets/try_catch_already_declared.ets new file mode 100644 index 0000000000000000000000000000000000000000..81a718b1216d20cff6c6eb00c6b894779ecc47d6 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/try_catch_already_declared.ets @@ -0,0 +1,21 @@ +/* + * 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. + */ + +try { +} catch (a) { + let a = 1 +} + +/* @@? 18:9 Error TypeError: Variable 'a' has already been declared. */ diff --git a/ets2panda/test/ast/compiler/ets/type_alise_with_lambda.ets b/ets2panda/test/ast/compiler/ets/type_alise_with_lambda.ets new file mode 100644 index 0000000000000000000000000000000000000000..2e3cfa1bb12844d6746677bfd317c94d1c1295c1 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/type_alise_with_lambda.ets @@ -0,0 +1,20 @@ +/* + * 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. + */ + +export type L T> + +/* @@? 16:26 Error TypeError: Cannot find type 'T'. */ +/* @@? 21:1 Error SyntaxError: Expected '=', got 'eos'. */ +/* @@? 21:1 Error SyntaxError: Invalid Type. */ diff --git a/ets2panda/varbinder/scope.cpp b/ets2panda/varbinder/scope.cpp index ba3d89ec9cd16669cf75654a5c4623568d417e40..5d9f77368a8fba1360fb24e16ce13ab74125b9df 100644 --- a/ets2panda/varbinder/scope.cpp +++ b/ets2panda/varbinder/scope.cpp @@ -1077,6 +1077,15 @@ Variable *CatchScope::AddBinding(ArenaAllocator *allocator, Variable *currentVar return AddLocal(allocator, currentVariable, newDecl, extension); } +Variable *CatchScope::FindLocal(const util::StringView &name, ResolveBindingOptions options) const +{ + auto res = Bindings().find(name); + if (res == Bindings().end()) { + return paramScope_->FindLocal(name, options); + } + return res->second; +} + template Variable *Scope::PropagateBinding(ArenaAllocator *allocator, util::StringView name, Args &&...args) { diff --git a/ets2panda/varbinder/scope.h b/ets2panda/varbinder/scope.h index 6e75a9c6df3695604a236ed73ba51e4753dd9524..e42dd24f69e900b77a2943bd9ccf0051c9f59ebe 100644 --- a/ets2panda/varbinder/scope.h +++ b/ets2panda/varbinder/scope.h @@ -778,6 +778,7 @@ public: Variable *AddBinding(ArenaAllocator *allocator, Variable *currentVariable, Decl *newDecl, [[maybe_unused]] ScriptExtension extension) override; + Variable *FindLocal(const util::StringView &name, ResolveBindingOptions options) const override; }; class LoopScope;