From 55664a8288c4dfeb811e62fa26984834ea0748f1 Mon Sep 17 00:00:00 2001 From: xuxinjie4 Date: Wed, 23 Jul 2025 19:00:28 +0800 Subject: [PATCH] Fix serval crash Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICODE9?from=project-issue Signed-off-by: xuxinjie4 --- ets2panda/parser/ETSparserClasses.cpp | 3 +++ .../compiler/ets/invalid_access_modifier.ets | 27 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 ets2panda/test/ast/compiler/ets/invalid_access_modifier.ets diff --git a/ets2panda/parser/ETSparserClasses.cpp b/ets2panda/parser/ETSparserClasses.cpp index 5b486495427..a1dbeeea650 100644 --- a/ets2panda/parser/ETSparserClasses.cpp +++ b/ets2panda/parser/ETSparserClasses.cpp @@ -223,6 +223,9 @@ std::tuple ETSParser::ParseClassMemberAccessModif accessFlag = ir::ModifierFlags::INTERNAL_PROTECTED; break; } + case lexer::TokenType::EOS: { // process invalid tokenType + return {ir::ModifierFlags::NONE, false, false}; + } default: { ES2PANDA_UNREACHABLE(); } diff --git a/ets2panda/test/ast/compiler/ets/invalid_access_modifier.ets b/ets2panda/test/ast/compiler/ets/invalid_access_modifier.ets new file mode 100644 index 00000000000..14f2dbbba75 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/invalid_access_modifier.ets @@ -0,0 +1,27 @@ +/* + * 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. + */ + +class A{ + private \\\\foo(){} +} + +/* @@? 17:13 Error SyntaxError: Invalid character. */ +/* @@? 17:13 Error SyntaxError: Access modifier must precede field and method modifiers. */ +/* @@? 17:14 Error SyntaxError: Invalid character. */ +/* @@? 17:14 Error SyntaxError: Access modifier must precede field and method modifiers. */ +/* @@? 17:15 Error SyntaxError: Invalid character. */ +/* @@? 17:15 Error SyntaxError: Access modifier must precede field and method modifiers. */ +/* @@? 17:16 Error SyntaxError: Invalid character. */ +/* @@? 17:16 Error SyntaxError: Access modifier must precede field and method modifiers. */ -- Gitee