From 64fc4b1e14452e44e7913eaf96cea74a577e76e8 Mon Sep 17 00:00:00 2001 From: yuanchaoxuan Date: Fri, 5 Sep 2025 10:35:51 +0800 Subject: [PATCH] Fix fuzz crash cased by repeated declaration Issue:https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICWHCG Signed-off-by: yuanchaoxuan --- ets2panda/checker/ets/helpers.cpp | 7 +++++ .../test/runtime/ets/fuzz/repeated_del.ets | 29 +++++++++++++++++++ .../declgen-ets2ts-runtime-ignored.txt | 1 + .../srcdumper/srcdumper-ets-ignored.txt | 1 + 4 files changed, 38 insertions(+) create mode 100644 ets2panda/test/runtime/ets/fuzz/repeated_del.ets diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index 313c539f82..7af150985b 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -2813,6 +2813,13 @@ ir::ClassProperty *ETSChecker::ClassPropToImplementationProp(ir::ClassProperty * fieldDecl->BindNode(classProp); auto fieldVar = scope->InstanceFieldScope()->AddDecl(ProgramAllocator(), fieldDecl, ScriptExtension::ETS); + if (fieldVar == nullptr) { + VarBinder()->ThrowRedeclaration(classProp->Id()->Start(), fieldDecl->Name(), fieldDecl->Type()); + fieldVar = + scope->InstanceFieldScope()->FindLocal(fieldDecl->Name(), varbinder::ResolveBindingOptions::BINDINGS); + } + ES2PANDA_ASSERT(fieldVar != nullptr); + fieldVar->AddFlag(varbinder::VariableFlags::PROPERTY); fieldVar->SetScope(scope->InstanceFieldScope()); diff --git a/ets2panda/test/runtime/ets/fuzz/repeated_del.ets b/ets2panda/test/runtime/ets/fuzz/repeated_del.ets new file mode 100644 index 0000000000..bd847c3ef9 --- /dev/null +++ b/ets2panda/test/runtime/ets/fuzz/repeated_del.ets @@ -0,0 +1,29 @@ +/* + * 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. + */ +/*--- + tags: [compile-only, negative] +---*/ +interface ReadonlySet { + set (: d) + get ‹(): b + + + } + + class Set implements ReadonlySet { + public ‹: *ERROR_TYPE*; + public : *ERROR_TYPE*; + } + \ No newline at end of file diff --git a/ets2panda/test/test-lists/declgenets2ts/ets-runtime/declgen-ets2ts-runtime-ignored.txt b/ets2panda/test/test-lists/declgenets2ts/ets-runtime/declgen-ets2ts-runtime-ignored.txt index 307994e6fe..7668597d9d 100644 --- a/ets2panda/test/test-lists/declgenets2ts/ets-runtime/declgen-ets2ts-runtime-ignored.txt +++ b/ets2panda/test/test-lists/declgenets2ts/ets-runtime/declgen-ets2ts-runtime-ignored.txt @@ -31,3 +31,4 @@ Multiline_string.ets Multiline_string_escape_char.ets run_ok_without_semicolon.ets async_lambda_return_type_test.ets +fuzz/repeated_del.ets diff --git a/ets2panda/test/test-lists/srcdumper/srcdumper-ets-ignored.txt b/ets2panda/test/test-lists/srcdumper/srcdumper-ets-ignored.txt index 8eb1ec055c..da725344e8 100644 --- a/ets2panda/test/test-lists/srcdumper/srcdumper-ets-ignored.txt +++ b/ets2panda/test/test-lists/srcdumper/srcdumper-ets-ignored.txt @@ -55,6 +55,7 @@ runtime/ets/fuzz/too_many_left_brace.ets runtime/ets/fuzz/too_many_left_square_brackets.ets runtime/ets/fuzz/too_many_new_expr.ets runtime/ets/fuzz/too_many_token.ets +runtime/ets/fuzz/repeated_del.ets ast/compiler/ets/DeclareIndexerTest.ets ast/parser/ets/import_tests/import_class_with_static_field/import_class_with_static_field.ets -- Gitee