From 2d5a603a47ab9366c13d259438812dda63163458 Mon Sep 17 00:00:00 2001 From: zengzengran Date: Mon, 21 Jul 2025 20:48:33 +0800 Subject: [PATCH] Fix invalid overloadlist crash Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICNFJM Description: Problem Description: When parsing the overload list, encountering "foo." triggers error handling, resulting in the member expression containing an incorrect identifier, which subsequently causes a compilation crash due to AsIdentifier. Do not parser "foo." to MemberExpression, skip "." , throws syntaxError and returns identifier Tested-by: ninja tests (passed) ets_testrunner (passed) Signed-off-by: zengzengran # --- ets2panda/parser/ETSparser.cpp | 1 + .../ets/first_match/invalid_declaration_5.ets | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 ets2panda/test/ast/compiler/ets/first_match/invalid_declaration_5.ets diff --git a/ets2panda/parser/ETSparser.cpp b/ets2panda/parser/ETSparser.cpp index 73ab94b616..77c5b41931 100644 --- a/ets2panda/parser/ETSparser.cpp +++ b/ets2panda/parser/ETSparser.cpp @@ -2240,6 +2240,7 @@ bool ETSParser::ParseOverloadListElement(ArenaVector &overload while (Lexer()->TryEatTokenType(lexer::TokenType::PUNCTUATOR_PERIOD)) { if (Lexer()->GetToken().Type() != lexer::TokenType::LITERAL_IDENT) { LogExpectedToken(lexer::TokenType::LITERAL_IDENT); + return false; } auto *identNode = AllocNode(Lexer()->GetToken().Ident(), Allocator()); identNode->SetRange(Lexer()->GetToken().Loc()); diff --git a/ets2panda/test/ast/compiler/ets/first_match/invalid_declaration_5.ets b/ets2panda/test/ast/compiler/ets/first_match/invalid_declaration_5.ets new file mode 100644 index 0000000000..c7a80816f0 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/first_match/invalid_declaration_5.ets @@ -0,0 +1,23 @@ +/* + * 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. + */ + +overload foo{ foo.,T,} + +/* @@? 16:19 Error SyntaxError: Unexpected token, expected an identifier. */ +/* @@? 16:19 Error TypeError: overloaded name must refer to an accessible method. */ +/* @@? 16:20 Error SyntaxError: Unexpected token, expected ',' or '}'. */ +/* @@? 16:20 Error TypeError: Unresolved reference T */ +/* @@? 16:21 Error SyntaxError: Unexpected token ','. */ +/* @@? 16:22 Error SyntaxError: Unexpected token '}'. */ -- Gitee