From 6ea9d3177c9c625f8b702c2f0c16be4f13019ce7 Mon Sep 17 00:00:00 2001 From: renguangxuan Date: Fri, 12 Sep 2025 15:15:12 +0800 Subject: [PATCH] Fix define interface in class Issue: #ICXQ3S Signed-off-by: renguangxuan --- ets2panda/parser/TypedParser.cpp | 8 --- .../test/ast/compiler/ets/interface_field.ets | 16 +---- .../ast/compiler/ets/interface_key_word.ets | 58 +++++++++++++++++++ .../ets/resolve_class_declaration.ets | 2 + 4 files changed, 62 insertions(+), 22 deletions(-) create mode 100644 ets2panda/test/ast/compiler/ets/interface_key_word.ets diff --git a/ets2panda/parser/TypedParser.cpp b/ets2panda/parser/TypedParser.cpp index a6ebafbfc7..0970d50fc4 100644 --- a/ets2panda/parser/TypedParser.cpp +++ b/ets2panda/parser/TypedParser.cpp @@ -608,14 +608,6 @@ ArenaVector TypedParser::ParseTypeLiteralOrInterfaceBody() if (!Lexer()->GetToken().NewLine()) { LogExpectedToken(lexer::TokenType::PUNCTUATOR_COMMA); } - - if (Lexer()->GetToken().IsKeyword() && (Lexer()->GetToken().Type() != lexer::TokenType::KEYW_STATIC && - Lexer()->GetToken().Type() != lexer::TokenType::KEYW_PRIVATE && - Lexer()->GetToken().Type() != lexer::TokenType::KEYW_DEFAULT)) { - Lexer()->GetToken().SetTokenType(lexer::TokenType::LITERAL_IDENT); - Lexer()->GetToken().SetTokenStr(ERROR_LITERAL); - } - continue; } diff --git a/ets2panda/test/ast/compiler/ets/interface_field.ets b/ets2panda/test/ast/compiler/ets/interface_field.ets index 096043467c..3982f0b10a 100644 --- a/ets2panda/test/ast/compiler/ets/interface_field.ets +++ b/ets2panda/test/ast/compiler/ets/interface_field.ets @@ -28,18 +28,6 @@ interface Todo { /* @@? 17:19 Error SyntaxError: Unexpected token, expected ',' or ')'. */ /* @@? 18:22 Error SyntaxError: Label must be followed by a loop statement. */ /* @@? 18:22 Error TypeError: Type name 'string' used in the wrong context */ -/* @@? 21:14 Error SyntaxError: Unexpected token, expected ','. */ -/* @@? 21:14 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ -/* @@? 21:25 Error TypeError: Cannot find type 'todo'. */ -/* @@? 21:29 Error SyntaxError: Unexpected token, expected ','. */ -/* @@? 21:29 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ -/* @@? 21:34 Error SyntaxError: Interface fields must have type annotation. */ -/* @@? 21:36 Error TypeError: Cannot find type 'fieldToUpdate'. */ -/* @@? 21:49 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ -/* @@? 21:49 Error SyntaxError: Unexpected token, expected ','. */ -/* @@? 21:64 Error SyntaxError: Unexpected token, expected '('. */ -/* @@? 21:66 Error SyntaxError: Unexpected token, expected ',' or ')'. */ -/* @@? 21:66 Error SyntaxError: Parameter declaration should have an explicit type annotation. */ -/* @@? 21:66 Error SyntaxError: Unexpected token, expected an identifier. */ +/* @@? 21:5 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ /* @@? 22:16 Error TypeError: need to specify target type for class composite */ -/* @@? 46:1 Error SyntaxError: Unexpected token, expected '}'. */ +/* @@? 34:1 Error SyntaxError: Unexpected token, expected '}'. */ diff --git a/ets2panda/test/ast/compiler/ets/interface_key_word.ets b/ets2panda/test/ast/compiler/ets/interface_key_word.ets new file mode 100644 index 0000000000..aea8259ebb --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/interface_key_word.ets @@ -0,0 +1,58 @@ +/* + * 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. + */ + +class CCC {} + +interface I { + foo() : boolean; + new() : CCC; + enum() : int; + await() : boolean; + async() : number; +} + +/* @@? 20:5 Error SyntaxError: Constructor signatures are not supported in interfaces, use methods instead! */ +/* @@? 20:5 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 20:9 Error SyntaxError: Interface fields must have type annotation. */ +/* @@? 20:11 Error SyntaxError: Invalid Type. */ +/* @@? 20:11 Error SyntaxError: Unexpected token, expected ','. */ +/* @@? 20:11 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 20:16 Error SyntaxError: Interface fields must have type annotation. */ +/* @@? 21:5 Error SyntaxError: Invalid Type. */ +/* @@? 21:5 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 21:10 Error SyntaxError: Interface fields must have type annotation. */ +/* @@? 21:12 Error SyntaxError: Invalid Type. */ +/* @@? 21:12 Error SyntaxError: Unexpected token, expected ','. */ +/* @@? 21:12 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 21:14 Error SyntaxError: Identifier expected. */ +/* @@? 21:14 Error SyntaxError: Unexpected token, expected ','. */ +/* @@? 21:14 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 21:17 Error SyntaxError: Identifier expected. */ +/* @@? 22:5 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 22:11 Error SyntaxError: Interface fields must have type annotation. */ +/* @@? 22:13 Error SyntaxError: Invalid Type. */ +/* @@? 22:13 Error SyntaxError: Unexpected token, expected ','. */ +/* @@? 22:13 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 22:15 Error SyntaxError: Identifier expected. */ +/* @@? 22:15 Error SyntaxError: Unexpected token, expected ','. */ +/* @@? 22:15 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 22:22 Error SyntaxError: Identifier expected. */ +/* @@? 23:5 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 23:11 Error SyntaxError: Interface fields must have type annotation. */ +/* @@? 23:13 Error SyntaxError: Invalid Type. */ +/* @@? 23:13 Error SyntaxError: Unexpected token, expected ','. */ +/* @@? 23:13 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 23:21 Error SyntaxError: Interface fields must have type annotation. */ +/* @@? 24:1 Error SyntaxError: Invalid Type. */ diff --git a/ets2panda/test/ast/compiler/ets/resolve_class_declaration.ets b/ets2panda/test/ast/compiler/ets/resolve_class_declaration.ets index 97180f8beb..9551d3fcae 100644 --- a/ets2panda/test/ast/compiler/ets/resolve_class_declaration.ets +++ b/ets2panda/test/ast/compiler/ets/resolve_class_declaration.ets @@ -26,3 +26,5 @@ interface I { /* @@? 17:31 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ /* @@? 17:41 Error SyntaxError: Interface fields must have type annotation. */ /* @@? 18:5 Error SyntaxError: Invalid Type. */ +/* @@? 18:5 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 18:11 Error SyntaxError: Identifier expected. */ -- Gitee