From eaa802dadecd638281ec98acf53ca0bab5c1c5b1 Mon Sep 17 00:00:00 2001 From: daizihan Date: Wed, 16 Jul 2025 15:54:05 +0800 Subject: [PATCH] Fix fuzz crashes Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICMQ2L?from=project-issue Signed-off-by: daizihan --- ets2panda/checker/types/ets/etsObjectType.cpp | 9 ++--- .../lowering/scopesInit/scopesInitPhase.cpp | 1 + .../test/ast/compiler/ets/bad_call_setter.ets | 35 +++++++++++++++++++ .../ets/try_catch_already_declared.ets | 21 +++++++++++ .../compiler/ets/type_alise_with_lambda.ets | 20 +++++++++++ ets2panda/varbinder/scope.cpp | 9 +++++ ets2panda/varbinder/scope.h | 1 + 7 files changed, 90 insertions(+), 6 deletions(-) create mode 100644 ets2panda/test/ast/compiler/ets/bad_call_setter.ets create mode 100644 ets2panda/test/ast/compiler/ets/try_catch_already_declared.ets create mode 100644 ets2panda/test/ast/compiler/ets/type_alise_with_lambda.ets diff --git a/ets2panda/checker/types/ets/etsObjectType.cpp b/ets2panda/checker/types/ets/etsObjectType.cpp index b07059d274..479bce100a 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 4d386ae30b..4e0606e170 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 0000000000..2bfd2c9474 --- /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 0000000000..81a718b121 --- /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 0000000000..2e3cfa1bb1 --- /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 ba3d89ec9c..5d9f77368a 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 6e75a9c6df..e42dd24f69 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; -- Gitee