diff --git a/ets2panda/checker/types/ets/etsObjectType.cpp b/ets2panda/checker/types/ets/etsObjectType.cpp index ebca1b901cbae2ac7679e86607c71a64d59e8c0f..1d42b6745b67e535f5e49972712ccb531f04eec8 100644 --- a/ets2panda/checker/types/ets/etsObjectType.cpp +++ b/ets2panda/checker/types/ets/etsObjectType.cpp @@ -319,11 +319,10 @@ bool ETSObjectType::ReplaceArgumentInSignature(std::vector &signatu void ETSObjectType::AddSignatureFromFunction(std::vector &signatures, PropertySearchFlags flags, ETSChecker *checker, varbinder::LocalVariable *found) const { - if (found == nullptr || found->TsType()->IsTypeError()) { + if (found == nullptr || !found->TsType()->IsETSFunctionType()) { return; } - ES2PANDA_ASSERT(found->TsType()->IsETSFunctionType()); for (auto *it : found->TsType()->AsETSFunctionType()->CallSignatures()) { if (std::find(signatures.begin(), signatures.end(), it) != signatures.end()) { continue; diff --git a/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp b/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp index 7e9deaf04ab8a744214980b18e323ef38e217ecf..d02274ff1f13745ccda4c8c013f8aaffb699c180 100644 --- a/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp +++ b/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp @@ -1252,6 +1252,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 1e1c31129136da31a9d142b2448a6d2b6813b02e..903b652741d54ba2da122e3a6a035e3cf68e8a65 100644 --- a/ets2panda/varbinder/scope.cpp +++ b/ets2panda/varbinder/scope.cpp @@ -1093,6 +1093,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;