From cbd7b59132cb454c282b9de256605389d4cbb7eb Mon Sep 17 00:00:00 2001 From: zengzengran Date: Thu, 7 Aug 2025 15:21:20 +0800 Subject: [PATCH] Fix incorrect format NotNullable node crash Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICRQ5N Description: Calling ParseTypeAnnotationNoPreferParam(), if source code with incorrect format, may return nullptr, leading to a compilation crash when subsequently creating ETSNonNullosjTypeNode. Should return brokenType instead of nullptr. Tested-by: ninja tests (passed) ets_testrunner (passed) Signed-off-by: zengzengran # --- ets2panda/parser/ETSparserTypes.cpp | 2 +- .../test/ast/parser/ets/notnullable_neg.ets | 41 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 ets2panda/test/ast/parser/ets/notnullable_neg.ets diff --git a/ets2panda/parser/ETSparserTypes.cpp b/ets2panda/parser/ETSparserTypes.cpp index 0567f0561d..d4439b4731 100644 --- a/ets2panda/parser/ETSparserTypes.cpp +++ b/ets2panda/parser/ETSparserTypes.cpp @@ -318,7 +318,7 @@ std::pair ETSParser::ParseNonNullableType(TypeAnnotationPa Lexer()->NextToken(); // eat NonNullable ExpectToken(lexer::TokenType::PUNCTUATOR_LESS_THAN, true); - auto *const typeAnnotation = ParseTypeAnnotationNoPreferParam(options); + auto *const typeAnnotation = ParseTypeAnnotation(options); ParsePunctuatorGreaterThan(); return std::make_pair(AllocNode(typeAnnotation, Allocator()), true); } diff --git a/ets2panda/test/ast/parser/ets/notnullable_neg.ets b/ets2panda/test/ast/parser/ets/notnullable_neg.ets new file mode 100644 index 0000000000..b48602f1bb --- /dev/null +++ b/ets2panda/test/ast/parser/ets/notnullable_neg.ets @@ -0,0 +1,41 @@ +/* + * 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. + */ + +function main() { + let foo = (p: T): NonNullable<<<<<<<<<<<<<<<<<<<<<<<<<< =>p; +} + +/* @@? 17:15 Error SyntaxError: Type cast syntax '' is not supported, please use 'as' keyword instead */ +/* @@? 17:20 Error SyntaxError: Unexpected token, expected ')'. */ +/* @@? 17:22 Error SyntaxError: Unexpected token 'T'. */ +/* @@? 17:22 Error TypeError: Unresolved reference T */ +/* @@? 17:23 Error SyntaxError: Unexpected token ')'. */ +/* @@? 17:24 Error SyntaxError: Unexpected token ':'. */ +/* @@? 17:26 Error SyntaxError: Unexpected token 'NonNullable'. */ +/* @@? 17:26 Error TypeError: Unresolved reference NonNullable */ +/* @@? 17:37 Error SyntaxError: Expected '>', got '<<'. */ +/* @@? 17:37 Error SyntaxError: Expected '<', got '<<'. */ +/* @@? 17:37 Error SyntaxError: Expected '>', got '<<'. */ +/* @@? 17:37 Error SyntaxError: Expected '<', got '<<'. */ +/* @@? 17:39 Error SyntaxError: Unexpected token '<<'. */ +/* @@? 17:43 Error SyntaxError: Unexpected token '<<'. */ +/* @@? 17:47 Error SyntaxError: Unexpected token '<<'. */ +/* @@? 17:51 Error SyntaxError: Unexpected token '<<'. */ +/* @@? 17:55 Error SyntaxError: Unexpected token '<<'. */ +/* @@? 17:59 Error SyntaxError: Unexpected token '<<'. */ +/* @@? 17:63 Error SyntaxError: Type cast syntax '' is not supported, please use 'as' keyword instead */ +/* @@? 17:67 Error SyntaxError: Unexpected token '=>'. */ +/* @@? 17:69 Error SyntaxError: Unexpected token 'p'. */ +/* @@? 17:69 Error TypeError: Unresolved reference p */ -- Gitee