From 57e631dc2a60b95b4192c56b727f6c1ebd7c5147 Mon Sep 17 00:00:00 2001 From: oh-rgx Date: Wed, 9 Jul 2025 16:46:54 +0800 Subject: [PATCH] Fix createPartial crash Issue: #ICL587 Signed-off-by: oh-rgx --- ets2panda/parser/ETSparserClasses.cpp | 3 +- .../ast/compiler/ets/interface_partial.ets | 48 +++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 ets2panda/test/ast/compiler/ets/interface_partial.ets diff --git a/ets2panda/parser/ETSparserClasses.cpp b/ets2panda/parser/ETSparserClasses.cpp index 70df433251..57f22cdbca 100644 --- a/ets2panda/parser/ETSparserClasses.cpp +++ b/ets2panda/parser/ETSparserClasses.cpp @@ -919,7 +919,8 @@ ir::AstNode *ETSParser::ParseInterfaceField() ir::TypeNode *typeAnnotation = nullptr; if (!Lexer()->TryEatTokenType(lexer::TokenType::PUNCTUATOR_COLON) && - Lexer()->GetToken().Type() != lexer::TokenType::LITERAL_IDENT) { + Lexer()->GetToken().Type() != lexer::TokenType::LITERAL_IDENT && + Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_RIGHT_BRACE) { // interfaces3.ets LogError(diagnostic::INTERFACE_FIELDS_TYPE_ANNOTATION); diff --git a/ets2panda/test/ast/compiler/ets/interface_partial.ets b/ets2panda/test/ast/compiler/ets/interface_partial.ets new file mode 100644 index 0000000000..92e836ab1e --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/interface_partial.ets @@ -0,0 +1,48 @@ +/* + * 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. + */ + +interface I { + arr +} + +function foo (bar: Partial) { + if (bar.var_one != undefined) { + bar.var_one = "asddsf"; + } +} + +function main() { + let a : I = {var_one: "initial_var_one", var_two: "initial_var_two_a"}; + foo(a.var_one); + let a : I = {var_two: "initial_var_two_b"}; + foo(break.var_one); +} + +/* @@? 18:1 Error SyntaxError: Invalid Type. */ +/* @@? 21:13 Error TypeError: Property 'var_one' does not exist on type 'I$partial' */ +/* @@? 22:13 Error TypeError: Property 'var_one' does not exist on type 'I$partial' */ +/* @@? 27:18 Error TypeError: type I has no property named var_one */ +/* @@? 28:11 Error TypeError: Property 'var_one' does not exist on type 'I' */ +/* @@? 29:9 Error TypeError: Variable 'a' has already been declared. */ +/* @@? 29:18 Error TypeError: type I has no property named var_two */ +/* @@? 30:9 Error SyntaxError: Unexpected token 'break'. */ +/* @@? 30:9 Error SyntaxError: Unexpected token, expected ',' or ')'. */ +/* @@? 30:9 Error SyntaxError: Unexpected token 'break'. */ +/* @@? 30:14 Error SyntaxError: Unexpected token, expected an identifier. */ +/* @@? 30:15 Error SyntaxError: Unexpected token 'var_one'. */ +/* @@? 30:15 Error TypeError: Unresolved reference var_one */ +/* @@? 30:22 Error SyntaxError: Unexpected token ')'. */ +/* @@? 30:22 Error SyntaxError: Unexpected token ')'. */ +/* @@? 30:22 Error SyntaxError: Unexpected token ')'. */ -- Gitee