diff --git a/ets2panda/checker/types/ets/etsObjectType.cpp b/ets2panda/checker/types/ets/etsObjectType.cpp index a177b5b38f29cd87aaa697b37b731c6e448fe9bb..b6bddcd9b16b79efaa194385e3dec637d59f05fd 100644 --- a/ets2panda/checker/types/ets/etsObjectType.cpp +++ b/ets2panda/checker/types/ets/etsObjectType.cpp @@ -237,16 +237,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); } } @@ -263,8 +261,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 64d1105ae54deaa56dd2b6e3f1970543d70d8209..fe52e99f9c92d17d22f0c89cd67b8c8f6a03ec62 100644 --- a/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp +++ b/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp @@ -1152,6 +1152,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..3b39e198c9b2f0474894efc6606986117daa8b22 --- /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 'end of stream'. */ +/* @@? 21:1 Error SyntaxError: Invalid Type. */ diff --git a/ets2panda/varbinder/scope.cpp b/ets2panda/varbinder/scope.cpp index ac412d9f836469ab1dc6caf80566ac5c09420c89..49b0538b7bd08e01d151b7cc164c31b28e82211e 100644 --- a/ets2panda/varbinder/scope.cpp +++ b/ets2panda/varbinder/scope.cpp @@ -1090,6 +1090,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 0ed9b1296812c238f5bbfac104f3a083ea5b4c64..7e671e719f56c9e52edea5cba58d5cc7d9e0ea19 100644 --- a/ets2panda/varbinder/scope.h +++ b/ets2panda/varbinder/scope.h @@ -790,6 +790,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;