From 653f9226144d92b4281df7db0e09d4dcc08b7f3b Mon Sep 17 00:00:00 2001 From: oh-rgx Date: Wed, 9 Jul 2025 16:31:54 +0800 Subject: [PATCH] Fix createPartial crash Issue: #ICL4IM Signed-off-by: oh-rgx --- ets2panda/parser/ETSparserClasses.cpp | 3 +- .../ast/compiler/ets/interface_partial.ets | 40 +++++++++++++++++++ 2 files changed, 42 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 a1cbd70d36..9169fcc0f2 100644 --- a/ets2panda/parser/ETSparserClasses.cpp +++ b/ets2panda/parser/ETSparserClasses.cpp @@ -994,7 +994,8 @@ ir::ModifierFlags ETSParser::ParseInterfaceMethodModifiers() ir::TypeNode *ETSParser::ParseInterfaceTypeAnnotation(ir::Identifier *name) { 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) { LogError(diagnostic::INTERFACE_FIELDS_TYPE_ANNOTATION); Lexer()->GetToken().SetTokenType(lexer::TokenType::PUNCTUATOR_COLON); Lexer()->NextToken(); 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..5e85493e9d --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/interface_partial.ets @@ -0,0 +1,40 @@ +/* + * 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'. */ -- Gitee