From e8241813e643e312b1ff520e021ad4b70dea3503 Mon Sep 17 00:00:00 2001 From: Janos Pantos Date: Wed, 25 Jun 2025 11:17:38 +0200 Subject: [PATCH] Fix invalid local enum declaration parsing Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICHS52 Fixes internal issue #26725 Change-Id: Ibbdc4865693c5327bb46e3fba489a094e38990dc Signed-off-by: Janos Pantos --- ets2panda/parser/ETSparser.cpp | 3 +++ ets2panda/test/ast/parser/ets/local-enum.ets | 22 ++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 ets2panda/test/ast/parser/ets/local-enum.ets diff --git a/ets2panda/parser/ETSparser.cpp b/ets2panda/parser/ETSparser.cpp index fff197fa75..bd175a4208 100644 --- a/ets2panda/parser/ETSparser.cpp +++ b/ets2panda/parser/ETSparser.cpp @@ -610,6 +610,9 @@ ir::AstNode *ETSParser::ParseInnerTypeDeclaration(ir::ModifierFlags memberModifi Lexer()->GetToken().SetTokenType(Lexer()->GetToken().KeywordType()); ir::AstNode *typeDecl = ParseTypeDeclaration(true); + if (typeDecl == nullptr) { + return nullptr; + } memberModifiers &= (ir::ModifierFlags::PUBLIC | ir::ModifierFlags::PROTECTED | ir::ModifierFlags::PRIVATE | ir::ModifierFlags::INTERNAL); typeDecl->AddModifier(memberModifiers); diff --git a/ets2panda/test/ast/parser/ets/local-enum.ets b/ets2panda/test/ast/parser/ets/local-enum.ets new file mode 100644 index 0000000000..2e3a21b49c --- /dev/null +++ b/ets2panda/test/ast/parser/ets/local-enum.ets @@ -0,0 +1,22 @@ +/* + * 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 { + /* @@ label */enum E { + C + } +} + +/* @@@ label Error SyntaxError: Unexpected token. A constructor, method, accessor, or property was expected. */ -- Gitee