From fde30c386391225703f7d1c63821d7ec70de200e Mon Sep 17 00:00:00 2001 From: zmw Date: Sat, 5 Jul 2025 17:36:51 +0800 Subject: [PATCH] Fix newExpr multi dot crash Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICKAX7 Description: Fix nexExpr multi dot crash Signed-off-by: zmw Signed-off-by: tengtengh --- ets2panda/parser/ETSparser.cpp | 4 ++++ .../ets/new_expr_with_succesive_multi_dot.ets | 24 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 ets2panda/test/ast/compiler/ets/new_expr_with_succesive_multi_dot.ets diff --git a/ets2panda/parser/ETSparser.cpp b/ets2panda/parser/ETSparser.cpp index 5364fc13da..c4aecfef86 100644 --- a/ets2panda/parser/ETSparser.cpp +++ b/ets2panda/parser/ETSparser.cpp @@ -880,6 +880,10 @@ ir::TypeNode *ETSParser::ParseTypeReference(TypeAnnotationParsingOptions *option while (true) { auto partPos = Lexer()->GetToken().Start(); auto [typeName, typeParams] = ParseTypeReferencePart(options); + if (typeName == nullptr) { + typeName = AllocBrokenExpression(partPos); + } + typeRefPart = AllocNode(typeName, typeParams, typeRefPart, Allocator()); typeRefPart->SetRange({partPos, Lexer()->GetToken().End()}); diff --git a/ets2panda/test/ast/compiler/ets/new_expr_with_succesive_multi_dot.ets b/ets2panda/test/ast/compiler/ets/new_expr_with_succesive_multi_dot.ets new file mode 100644 index 0000000000..0613f1132d --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/new_expr_with_succesive_multi_dot.ets @@ -0,0 +1,24 @@ +/* + * 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. + */ + +importet lock1 = new ArkTSUt../main; + +/* @@? 16:1 Error TypeError: Unresolved reference importet */ +/* @@? 16:10 Error SyntaxError: Unexpected token 'lock1'. */ +/* @@? 16:10 Error TypeError: Unresolved reference lock1 */ +/* @@? 16:18 Error TypeError: Bad operand type, the types of the operands must be numeric type. */ +/* @@? 16:30 Error SyntaxError: Identifier expected. */ +/* @@? 16:31 Error TypeError: Invalid type reference. */ +/* @@? 16:32 Error TypeError: Function name 'main' used in the wrong context */ -- Gitee