From adf210e5843bfa9475eb472b0b79edde931b4534 Mon Sep 17 00:00:00 2001 From: zengzengran Date: Wed, 9 Jul 2025 17:08:54 +0800 Subject: [PATCH] Fix declare class cannot use overload alias Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICM9AB Description: Error filtering declare modifier, it is necessary to allow classes to use overload alias even when the declare modifier is applied. Tests: ninja tests (passed) ets_testrunner (passed) Signed-off-by: anjiaqi --- ets2panda/parser/ETSparser.cpp | 5 +++-- .../ets/first_match/declare_class.ets | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 ets2panda/test/ast/compiler/ets/first_match/declare_class.ets diff --git a/ets2panda/parser/ETSparser.cpp b/ets2panda/parser/ETSparser.cpp index 5541ac57d5..1a478c2e45 100644 --- a/ets2panda/parser/ETSparser.cpp +++ b/ets2panda/parser/ETSparser.cpp @@ -2206,8 +2206,9 @@ void ETSParser::CheckDeclare() void ETSParser::ValidateOverloadDeclarationModifiers(ir::ModifierFlags modifiers) { - ir::ModifierFlags allowModifiers = - ir::ModifierFlags::STATIC | ir::ModifierFlags::ASYNC | ir::ModifierFlags::ACCESS | ir::ModifierFlags::EXPORTED; + ir::ModifierFlags allowModifiers = ir::ModifierFlags::STATIC | ir::ModifierFlags::ASYNC | + ir::ModifierFlags::ACCESS | ir::ModifierFlags::EXPORTED | + ir::ModifierFlags::DECLARE; if ((modifiers & ~allowModifiers) != 0) { LogError(diagnostic::OVERLOAD_MODIFIERS); } diff --git a/ets2panda/test/ast/compiler/ets/first_match/declare_class.ets b/ets2panda/test/ast/compiler/ets/first_match/declare_class.ets new file mode 100644 index 0000000000..fa5734b298 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/first_match/declare_class.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 declare class A { + overload on{ on1, on2 } + on1(a: string): void + on2(a: number): void +} -- Gitee