From 08905513b8a7e137a13ba4ad73577b8ef984a5d4 Mon Sep 17 00:00:00 2001 From: Janos Pantos Date: Fri, 15 Aug 2025 15:19:46 +0200 Subject: [PATCH] Prohibit private interface field modifier Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICT1HG Fixes internal issue #24994 Change-Id: I5148b260d92166719d448729f4fc863957a3ff07 Signed-off-by: Janos Pantos --- ets2panda/parser/ETSparserClasses.cpp | 11 +++++-- .../ambient_interface_default_keyword02.ets | 5 ++- .../ast/compiler/ets/ambient_namesapce05.ets | 2 +- .../ets/interface-constructor-signatures.ets | 6 ++-- .../interface_ambient_call_signature_1.ets | 2 +- .../test/ast/compiler/ets/interface_field.ets | 6 ++-- .../compiler/ets/interface_property_scope.ets | 2 +- .../compiler/ets/optionalClassProperty1.ets | 2 ++ .../ets/resolve_class_declaration.ets | 4 +-- .../ets/Interface_variable_identifier.ets | 2 +- .../test/ast/parser/ets/InvalidClasses.ets | 7 ++-- .../test/ast/parser/ets/assign-func-iface.ets | 5 ++- ...late_initialization_with_initalizer_02.ets | 2 +- ...sis_invocation_setter_supposed_to_fail.ets | 4 +-- ...arenthesis_invocation_supposed_to_fail.ets | 4 +-- .../test/ast/parser/ets/interfaceAbstract.ets | 2 +- .../ets/interfaceMethodNativeModifier.ets | 5 ++- .../interfaceMethodPrivateStaticModifier.ets | 3 +- .../ets/interfaceMethodReadonlyModifier.ets | 2 +- .../ets/interfaceMethodStaticModifier.ets | 5 ++- .../ets/interface_ambient_indexer_2.ets | 4 +-- .../ets/interface_member_initialization.ets | 2 +- .../parser/ets/interface_parser_error_1.ets | 4 +-- .../parser/ets/interface_parser_error_2.ets | 4 +-- .../ets/interface_property_modifiers.ets | 32 +++++++++++++++++++ ...c_late_initialization_assignment_error.ets | 2 +- .../parser/ets/invalid_punctuator_format.ets | 4 +-- .../ets/keyword_after_readonly_interface.ets | 4 +-- ...erface-member-access-modifier-private1.ets | 1 + ...erface-member-access-modifier-private2.ets | 4 +-- ...face-member-access-modifier-protected1.ets | 2 +- ets2panda/test/ast/parser/ets/local_enum.ets | 2 +- .../test/ast/parser/ets/local_type_alias.ets | 2 +- .../ets/overloaded_method_as_value_neg.ets | 4 +-- .../ast/parser/ets/struct_in_interface.ets | 6 ++-- .../test/ast/parser/ets/user_defined_25.ets | 2 +- .../test/ast/parser/ets/user_defined_7.ets | 2 +- ets2panda/util/diagnostic/syntax.yaml | 5 +-- 38 files changed, 100 insertions(+), 67 deletions(-) create mode 100644 ets2panda/test/ast/parser/ets/interface_property_modifiers.ets diff --git a/ets2panda/parser/ETSparserClasses.cpp b/ets2panda/parser/ETSparserClasses.cpp index ec8a5af610..1ebee1b8da 100644 --- a/ets2panda/parser/ETSparserClasses.cpp +++ b/ets2panda/parser/ETSparserClasses.cpp @@ -960,19 +960,22 @@ ir::ModifierFlags ETSParser::ParseInterfaceMethodModifiers() LogError(diagnostic::LOCAL_CLASS_ACCESS_MOD, {}, Lexer()->GetToken().Start()); } } + + // NOTE(pantos): The 'private' modifier is only allowed for default methods, it is checked later for properties const auto keywordType = Lexer()->GetToken().KeywordType(); const bool isPrivate = (keywordType == lexer::TokenType::KEYW_PRIVATE); const bool isDefaultInAmbient = (keywordType == lexer::TokenType::KEYW_DEFAULT) && InAmbientContext(); if (!isPrivate) { if (!isDefaultInAmbient) { - LogError(diagnostic::UNEXPECTED_TOKEN_PRIVATE_ID); + LogError(diagnostic::IDENTIFIER_EXPECTED_HERE, {TokenToString(keywordType)}, Lexer()->GetToken().Start()); } if (keywordType == lexer::TokenType::KEYW_NEW) { LogError(diagnostic::ERROR_ARKTS_NO_INTERFACE_CONSTRUCTOR_SIGNATURES); } } Lexer()->NextToken(); - return isDefaultInAmbient ? ir::ModifierFlags::DEFAULT : ir::ModifierFlags::PRIVATE; + return isDefaultInAmbient ? ir::ModifierFlags::DEFAULT + : (isPrivate ? ir::ModifierFlags::PRIVATE : ir::ModifierFlags::PUBLIC); } ir::TypeNode *ETSParser::ParseInterfaceTypeAnnotation(ir::Identifier *name) @@ -1253,6 +1256,7 @@ ir::AstNode *ETSParser::ParseTypeLiteralOrInterfaceMember() return ParseInterfaceGetterSetterMethod(ir::ModifierFlags::PUBLIC); } + auto modLoc = Lexer()->GetToken().Start(); ir::ModifierFlags modifiers = ParseInterfaceMethodModifiers(); char32_t nextCp = Lexer()->Lookahead(); auto startLoc = Lexer()->GetToken().Start(); @@ -1284,6 +1288,9 @@ ir::AstNode *ETSParser::ParseTypeLiteralOrInterfaceMember() auto *field = ParseInterfaceField(); if (field != nullptr) { + if ((modifiers & ir::ModifierFlags::PRIVATE) != 0) { + LogError(diagnostic::IDENTIFIER_EXPECTED_HERE, {"private"}, modLoc); + } field->SetStart(startLoc); if (isReadonly) { field->AddModifier(ir::ModifierFlags::READONLY); diff --git a/ets2panda/test/ast/compiler/ets/ambient_interface_default_keyword02.ets b/ets2panda/test/ast/compiler/ets/ambient_interface_default_keyword02.ets index a644ed266b..99739fc83f 100644 --- a/ets2panda/test/ast/compiler/ets/ambient_interface_default_keyword02.ets +++ b/ets2panda/test/ast/compiler/ets/ambient_interface_default_keyword02.ets @@ -27,6 +27,5 @@ interface YYY { /* @@? 17:36 Error TypeError: Native, Abstract and Declare methods cannot have body. */ /* @@? 20:26 Error TypeError: Native, Abstract and Declare methods cannot have body. */ -/* @@? 24:7 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ -/* @@? 24:18 Error SyntaxError: Private interface methods must have body. */ -/* @@? 25:7 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 24:7 Error SyntaxError: Identifier expected, got 'default'. */ +/* @@? 25:7 Error SyntaxError: Identifier expected, got 'default'. */ diff --git a/ets2panda/test/ast/compiler/ets/ambient_namesapce05.ets b/ets2panda/test/ast/compiler/ets/ambient_namesapce05.ets index 99d90aafe3..8512fcfc13 100644 --- a/ets2panda/test/ast/compiler/ets/ambient_namesapce05.ets +++ b/ets2panda/test/ast/compiler/ets/ambient_namesapce05.ets @@ -21,5 +21,5 @@ declare namespace MySpace{ /* @@? 18:15 Error SyntaxError: Interface member initialization is prohibited. */ /* @@? 18:17 Error SyntaxError: Unexpected token, expected ','. */ -/* @@? 18:17 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 18:17 Error SyntaxError: Identifier expected, got 'number literal'. */ /* @@? 19:5 Error SyntaxError: Identifier expected. */ diff --git a/ets2panda/test/ast/compiler/ets/interface-constructor-signatures.ets b/ets2panda/test/ast/compiler/ets/interface-constructor-signatures.ets index 9d2fef2044..72657a795c 100644 --- a/ets2panda/test/ast/compiler/ets/interface-constructor-signatures.ets +++ b/ets2panda/test/ast/compiler/ets/interface-constructor-signatures.ets @@ -23,14 +23,14 @@ function fn(i: I) { return new i("hello") } -/* @@? 19:5 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 19:5 Error SyntaxError: Identifier expected, got 'new'. */ /* @@? 19:5 Error SyntaxError: Constructor signatures are not supported in interfaces, use methods instead! */ /* @@? 19:10 Error TypeError: Cannot find type 's'. */ /* @@? 19:11 Error SyntaxError: Unexpected token, expected ','. */ -/* @@? 19:11 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 19:11 Error SyntaxError: Identifier expected, got 'end of stream'. */ /* @@? 19:19 Error SyntaxError: Interface fields must have type annotation. */ /* @@? 19:20 Error SyntaxError: Invalid Type. */ /* @@? 19:20 Error SyntaxError: Unexpected token, expected ','. */ -/* @@? 19:20 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 19:20 Error SyntaxError: Identifier expected, got 'end of stream'. */ /* @@? 20:1 Error SyntaxError: Invalid Type. */ /* @@? 23:16 Error TypeError: Cannot find type 'i'. */ diff --git a/ets2panda/test/ast/compiler/ets/interface_ambient_call_signature_1.ets b/ets2panda/test/ast/compiler/ets/interface_ambient_call_signature_1.ets index f2a2037d53..23b238851c 100644 --- a/ets2panda/test/ast/compiler/ets/interface_ambient_call_signature_1.ets +++ b/ets2panda/test/ast/compiler/ets/interface_ambient_call_signature_1.ets @@ -18,5 +18,5 @@ } /* @@? 17:7 Error TypeError: Native and Declare methods should have explicit return type. */ /* @@? 17:21 Error SyntaxError: Unexpected token, expected ','. */ -/* @@? 17:21 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 17:21 Error SyntaxError: Identifier expected, got 'string'. */ /* @@? 18:3 Error SyntaxError: Identifier expected. */ \ No newline at end of file diff --git a/ets2panda/test/ast/compiler/ets/interface_field.ets b/ets2panda/test/ast/compiler/ets/interface_field.ets index 096043467c..c2e9213980 100644 --- a/ets2panda/test/ast/compiler/ets/interface_field.ets +++ b/ets2panda/test/ast/compiler/ets/interface_field.ets @@ -29,13 +29,13 @@ interface Todo { /* @@? 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:14 Error SyntaxError: Identifier expected, got 'identification literal'. */ /* @@? 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:29 Error SyntaxError: Identifier expected, got 'end of stream'. */ /* @@? 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: Identifier expected, got 'end of stream'. */ /* @@? 21:49 Error SyntaxError: Unexpected token, expected ','. */ /* @@? 21:64 Error SyntaxError: Unexpected token, expected '('. */ /* @@? 21:66 Error SyntaxError: Unexpected token, expected ',' or ')'. */ diff --git a/ets2panda/test/ast/compiler/ets/interface_property_scope.ets b/ets2panda/test/ast/compiler/ets/interface_property_scope.ets index 0c8647af1e..ed2b2c03b0 100644 --- a/ets2panda/test/ast/compiler/ets/interface_property_scope.ets +++ b/ets2panda/test/ast/compiler/ets/interface_property_scope.ets @@ -22,6 +22,6 @@ interface itf0{ /* @@? 18:6 Error TypeError: Cannot find type 'Anno'. */ /* @@? 18:11 Error SyntaxError: Invalid value for annotation field, expected a constant literal. */ /* @@? 18:45 Error SyntaxError: Expected ')', got ','. */ -/* @@? 18:45 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 18:45 Error SyntaxError: Identifier expected, got 'end of stream'. */ /* @@? 18:76 Error SyntaxError: Interface fields must have type annotation. */ /* @@? 19:1 Error SyntaxError: Invalid Type. */ diff --git a/ets2panda/test/ast/compiler/ets/optionalClassProperty1.ets b/ets2panda/test/ast/compiler/ets/optionalClassProperty1.ets index 736288ff1d..3224058292 100644 --- a/ets2panda/test/ast/compiler/ets/optionalClassProperty1.ets +++ b/ets2panda/test/ast/compiler/ets/optionalClassProperty1.ets @@ -95,3 +95,5 @@ class C7 implements I72 { class C8 implements I { a ?: Array } + +/* @@? 57:5 Error SyntaxError: Identifier expected, got 'private'. */ diff --git a/ets2panda/test/ast/compiler/ets/resolve_class_declaration.ets b/ets2panda/test/ast/compiler/ets/resolve_class_declaration.ets index 97180f8beb..71569d910a 100644 --- a/ets2panda/test/ast/compiler/ets/resolve_class_declaration.ets +++ b/ets2panda/test/ast/compiler/ets/resolve_class_declaration.ets @@ -20,9 +20,9 @@ interface I { /* @@? 17:20 Error SyntaxError: Interface fields must have type annotation. */ /* @@? 17:30 Error SyntaxError: Unexpected token, expected ','. */ -/* @@? 17:30 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 17:30 Error SyntaxError: Identifier expected, got 'end of stream'. */ /* @@? 17:31 Error SyntaxError: Identifier expected. */ /* @@? 17:31 Error SyntaxError: Unexpected token, expected ','. */ -/* @@? 17:31 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 17:31 Error SyntaxError: Identifier expected, got 'end of stream'. */ /* @@? 17:41 Error SyntaxError: Interface fields must have type annotation. */ /* @@? 18:5 Error SyntaxError: Invalid Type. */ diff --git a/ets2panda/test/ast/parser/ets/Interface_variable_identifier.ets b/ets2panda/test/ast/parser/ets/Interface_variable_identifier.ets index 4c21f812ec..dabebff9fd 100644 --- a/ets2panda/test/ast/parser/ets/Interface_variable_identifier.ets +++ b/ets2panda/test/ast/parser/ets/Interface_variable_identifier.ets @@ -21,4 +21,4 @@ interface A{ /* @@? 18:11 Error SyntaxError: Interface fields must have type annotation. */ /* @@? 18:12 Error SyntaxError: Invalid Type. */ /* @@? 18:12 Error SyntaxError: Unexpected token, expected ','. */ -/* @@? 18:12 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 18:12 Error SyntaxError: Identifier expected, got 'end of stream'. */ diff --git a/ets2panda/test/ast/parser/ets/InvalidClasses.ets b/ets2panda/test/ast/parser/ets/InvalidClasses.ets index 131be93eea..9e9343b6b4 100644 --- a/ets2panda/test/ast/parser/ets/InvalidClasses.ets +++ b/ets2panda/test/ast/parser/ets/InvalidClasses.ets @@ -118,12 +118,11 @@ interface I1 { /* @@? 65:5 Error SyntaxError: Illegal start of INTERFACE expression. */ /* @@? 66:9 Error SyntaxError: Local class or interface declaration members can not have access modifies. */ /* @@? 66:18 Error SyntaxError: Private interface methods must have body. */ -/* @@? 67:9 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ -/* @@? 67:16 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 67:9 Error SyntaxError: Identifier expected, got 'static'. */ /* @@? 67:16 Error SyntaxError: Unexpected token, expected ','. */ +/* @@? 67:16 Error SyntaxError: Identifier expected, got 'static'. */ /* @@? 67:16 Error SyntaxError: Identifier expected. */ -/* @@? 67:24 Error SyntaxError: Private interface methods must have body. */ -/* @@? 72:5 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 72:5 Error SyntaxError: Identifier expected, got 'class'. */ /* @@? 72:13 Error SyntaxError: Interface fields must have type annotation. */ /* @@? 72:14 Error SyntaxError: Invalid Type. */ /* @@? 74:5 Error SyntaxError: Extension Getter can only have 1 parameter. */ diff --git a/ets2panda/test/ast/parser/ets/assign-func-iface.ets b/ets2panda/test/ast/parser/ets/assign-func-iface.ets index b79b795449..fa29a6e6ce 100644 --- a/ets2panda/test/ast/parser/ets/assign-func-iface.ets +++ b/ets2panda/test/ast/parser/ets/assign-func-iface.ets @@ -14,8 +14,7 @@ */ interface Foo { - /* @@ label */async foo/* @@ label1 */(): Promise; + /* @@ label */async foo(): Promise; } -/* @@@ label Error SyntaxError: Unexpected token, expected 'private' or identifier. */ -/* @@@ label1 Error SyntaxError: Private interface methods must have body. */ +/* @@@ label Error SyntaxError: Identifier expected, got 'async'. */ diff --git a/ets2panda/test/ast/parser/ets/class_late_initialization_with_initalizer_02.ets b/ets2panda/test/ast/parser/ets/class_late_initialization_with_initalizer_02.ets index 14556b9e58..d37fc87aa7 100644 --- a/ets2panda/test/ast/parser/ets/class_late_initialization_with_initalizer_02.ets +++ b/ets2panda/test/ast/parser/ets/class_late_initialization_with_initalizer_02.ets @@ -19,5 +19,5 @@ interface A { /* @@? 17:16 Error SyntaxError: Interface member initialization is prohibited. */ /* @@? 17:18 Error SyntaxError: Unexpected token, expected ','. */ -/* @@? 17:18 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 17:18 Error SyntaxError: Identifier expected, got 'string literal'. */ /* @@? 18:1 Error SyntaxError: Identifier expected. */ diff --git a/ets2panda/test/ast/parser/ets/double_parenthesis_invocation_setter_supposed_to_fail.ets b/ets2panda/test/ast/parser/ets/double_parenthesis_invocation_setter_supposed_to_fail.ets index 9ed1927382..743990625e 100644 --- a/ets2panda/test/ast/parser/ets/double_parenthesis_invocation_setter_supposed_to_fail.ets +++ b/ets2panda/test/ast/parser/ets/double_parenthesis_invocation_setter_supposed_to_fail.ets @@ -19,8 +19,8 @@ interface Test { /* @@? 17:25 Error SyntaxError: Unexpected token '('. */ /* @@? 17:25 Error SyntaxError: Unexpected token, expected ','. */ -/* @@? 17:25 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 17:25 Error SyntaxError: Identifier expected, got 'end of stream'. */ /* @@? 17:26 Error SyntaxError: Identifier expected. */ /* @@? 17:26 Error SyntaxError: Unexpected token, expected ','. */ -/* @@? 17:26 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 17:26 Error SyntaxError: Identifier expected, got 'end of stream'. */ /* @@? 18:1 Error SyntaxError: Identifier expected. */ diff --git a/ets2panda/test/ast/parser/ets/double_parenthesis_invocation_supposed_to_fail.ets b/ets2panda/test/ast/parser/ets/double_parenthesis_invocation_supposed_to_fail.ets index db487af187..13e8057f3e 100644 --- a/ets2panda/test/ast/parser/ets/double_parenthesis_invocation_supposed_to_fail.ets +++ b/ets2panda/test/ast/parser/ets/double_parenthesis_invocation_supposed_to_fail.ets @@ -21,8 +21,8 @@ interface Test { /* @@? 18:5 Error TypeError: Function proc is already declared. */ /* @@? 18:11 Error SyntaxError: Unexpected token '('. */ /* @@? 18:11 Error SyntaxError: Unexpected token, expected ','. */ -/* @@? 18:11 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 18:11 Error SyntaxError: Identifier expected, got 'end of stream'. */ /* @@? 18:12 Error SyntaxError: Identifier expected. */ /* @@? 18:12 Error SyntaxError: Unexpected token, expected ','. */ -/* @@? 18:12 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 18:12 Error SyntaxError: Identifier expected, got 'end of stream'. */ /* @@? 19:1 Error SyntaxError: Identifier expected. */ diff --git a/ets2panda/test/ast/parser/ets/interfaceAbstract.ets b/ets2panda/test/ast/parser/ets/interfaceAbstract.ets index 4f1a56deb1..afd71e3dd2 100644 --- a/ets2panda/test/ast/parser/ets/interfaceAbstract.ets +++ b/ets2panda/test/ast/parser/ets/interfaceAbstract.ets @@ -17,4 +17,4 @@ interface Vehicle { private getHorsePower/* @@ label */(rpm: int, torque: int): int } -/* @@@ label Error SyntaxError: Private interface methods must have body. */ +/* @@@ label Error SyntaxError: Private interface methods must have body. */ diff --git a/ets2panda/test/ast/parser/ets/interfaceMethodNativeModifier.ets b/ets2panda/test/ast/parser/ets/interfaceMethodNativeModifier.ets index fd964d2e8d..f4e3a406f0 100644 --- a/ets2panda/test/ast/parser/ets/interfaceMethodNativeModifier.ets +++ b/ets2panda/test/ast/parser/ets/interfaceMethodNativeModifier.ets @@ -14,8 +14,7 @@ */ interface I { - /* @@ label */native foo/* @@ label1 */() + /* @@ label */native foo() } -/* @@@ label Error SyntaxError: Unexpected token, expected 'private' or identifier. */ -/* @@@ label1 Error SyntaxError: Private interface methods must have body. */ +/* @@@ label Error SyntaxError: Identifier expected, got 'native'. */ diff --git a/ets2panda/test/ast/parser/ets/interfaceMethodPrivateStaticModifier.ets b/ets2panda/test/ast/parser/ets/interfaceMethodPrivateStaticModifier.ets index 116bd826fb..b2e896848a 100644 --- a/ets2panda/test/ast/parser/ets/interfaceMethodPrivateStaticModifier.ets +++ b/ets2panda/test/ast/parser/ets/interfaceMethodPrivateStaticModifier.ets @@ -19,5 +19,4 @@ interface I { /* @@? 17:13 Error SyntaxError: Identifier expected. */ /* @@? 17:13 Error SyntaxError: Unexpected token, expected ','. */ -/* @@? 17:13 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ -/* @@? 17:23 Error SyntaxError: Private interface methods must have body. */ +/* @@? 17:13 Error SyntaxError: Identifier expected, got 'static'. */ diff --git a/ets2panda/test/ast/parser/ets/interfaceMethodReadonlyModifier.ets b/ets2panda/test/ast/parser/ets/interfaceMethodReadonlyModifier.ets index 39dcced0fd..9d4cf23b2b 100644 --- a/ets2panda/test/ast/parser/ets/interfaceMethodReadonlyModifier.ets +++ b/ets2panda/test/ast/parser/ets/interfaceMethodReadonlyModifier.ets @@ -20,5 +20,5 @@ interface I { /* @@? 17:17 Error SyntaxError: Interface fields must have type annotation. */ /* @@? 17:18 Error SyntaxError: Invalid Type. */ /* @@? 17:18 Error SyntaxError: Unexpected token, expected ','. */ -/* @@? 17:18 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 17:18 Error SyntaxError: Identifier expected, got 'end of stream'. */ /* @@? 18:1 Error SyntaxError: Identifier expected. */ \ No newline at end of file diff --git a/ets2panda/test/ast/parser/ets/interfaceMethodStaticModifier.ets b/ets2panda/test/ast/parser/ets/interfaceMethodStaticModifier.ets index 098caf8bb4..ec59242f2d 100644 --- a/ets2panda/test/ast/parser/ets/interfaceMethodStaticModifier.ets +++ b/ets2panda/test/ast/parser/ets/interfaceMethodStaticModifier.ets @@ -14,8 +14,7 @@ */ interface I { - /* @@ label */static foo/* @@ label1 */() + /* @@ label */static foo() } -/* @@@ label Error SyntaxError: Unexpected token, expected 'private' or identifier. */ -/* @@@ label1 Error SyntaxError: Private interface methods must have body. */ +/* @@@ label Error SyntaxError: Identifier expected, got 'static'. */ diff --git a/ets2panda/test/ast/parser/ets/interface_ambient_indexer_2.ets b/ets2panda/test/ast/parser/ets/interface_ambient_indexer_2.ets index 6789f5f098..77e7f5b1ae 100644 --- a/ets2panda/test/ast/parser/ets/interface_ambient_indexer_2.ets +++ b/ets2panda/test/ast/parser/ets/interface_ambient_indexer_2.ets @@ -24,8 +24,8 @@ declare interface A { /* @@? 17:20 Error SyntaxError: Invalid Type. */ /* @@? 17:20 Error SyntaxError: Return type of index signature from exported class or interface need to be identifier. */ /* @@? 17:20 Error SyntaxError: Unexpected token, expected ','. */ -/* @@? 17:20 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 17:20 Error SyntaxError: Identifier expected, got 'end of stream'. */ /* @@? 17:21 Error SyntaxError: Identifier expected. */ /* @@? 17:21 Error SyntaxError: Unexpected token, expected ','. */ -/* @@? 17:21 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 17:21 Error SyntaxError: Identifier expected, got 'end of stream'. */ /* @@? 18:1 Error SyntaxError: Invalid Type. */ diff --git a/ets2panda/test/ast/parser/ets/interface_member_initialization.ets b/ets2panda/test/ast/parser/ets/interface_member_initialization.ets index d96988046d..3af1b2d88d 100644 --- a/ets2panda/test/ast/parser/ets/interface_member_initialization.ets +++ b/ets2panda/test/ast/parser/ets/interface_member_initialization.ets @@ -24,5 +24,5 @@ function main() /* @@? 17:14 Error SyntaxError: Interface member initialization is prohibited. */ /* @@? 17:16 Error SyntaxError: Unexpected token, expected ','. */ -/* @@? 17:16 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 17:16 Error SyntaxError: Identifier expected, got 'number literal'. */ /* @@? 17:17 Error SyntaxError: Identifier expected. */ diff --git a/ets2panda/test/ast/parser/ets/interface_parser_error_1.ets b/ets2panda/test/ast/parser/ets/interface_parser_error_1.ets index 692ad1e69d..59b147e1cf 100644 --- a/ets2panda/test/ast/parser/ets/interface_parser_error_1.ets +++ b/ets2panda/test/ast/parser/ets/interface_parser_error_1.ets @@ -42,10 +42,10 @@ function mdin() { let a = new A(); /* @@? 19:1 Error SyntaxError: Illegal start of INTERFACE expression. */ /* @@? 20:5 Error SyntaxError: Identifier expected. */ /* @@? 20:14 Error SyntaxError: Unexpected token, expected ','. */ -/* @@? 20:14 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 20:14 Error SyntaxError: Identifier expected, got 'end of stream'. */ /* @@? 20:16 Error SyntaxError: Identifier expected. */ /* @@? 20:16 Error SyntaxError: Unexpected token, expected ','. */ -/* @@? 20:16 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 20:16 Error SyntaxError: Identifier expected, got 'boolean'. */ /* @@? 21:1 Error SyntaxError: Identifier expected. */ /* @@? 22:1 Error TypeError: Unresolved reference inter */ /* @@? 24:1 Error SyntaxError: Illegal start of CLASS expression. */ diff --git a/ets2panda/test/ast/parser/ets/interface_parser_error_2.ets b/ets2panda/test/ast/parser/ets/interface_parser_error_2.ets index b2f0dcd090..b0d947afd4 100644 --- a/ets2panda/test/ast/parser/ets/interface_parser_error_2.ets +++ b/ets2panda/test/ast/parser/ets/interface_parser_error_2.ets @@ -17,8 +17,8 @@ interface I { : boolean } -/* @@? 17:5 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 17:5 Error SyntaxError: Identifier expected, got 'end of stream'. */ /* @@? 17:7 Error SyntaxError: Identifier expected. */ /* @@? 17:7 Error SyntaxError: Unexpected token, expected ','. */ -/* @@? 17:7 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 17:7 Error SyntaxError: Identifier expected, got 'boolean'. */ /* @@? 18:1 Error SyntaxError: Identifier expected. */ diff --git a/ets2panda/test/ast/parser/ets/interface_property_modifiers.ets b/ets2panda/test/ast/parser/ets/interface_property_modifiers.ets new file mode 100644 index 0000000000..b82e95fb28 --- /dev/null +++ b/ets2panda/test/ast/parser/ets/interface_property_modifiers.ets @@ -0,0 +1,32 @@ +/** + * 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 { + f: number; + readonly f_ro: number; + + // invalid interface property modifiers + private f_priv: number; + protected f_prot: number; + public f_pub: number; + static f_stat: number; + default f_def: number; +} + +/* @@? 21:5 Error SyntaxError: Identifier expected, got 'private'. */ +/* @@? 22:5 Error SyntaxError: Identifier expected, got 'protected'. */ +/* @@? 23:5 Error SyntaxError: Identifier expected, got 'public'. */ +/* @@? 24:5 Error SyntaxError: Identifier expected, got 'static'. */ +/* @@? 25:5 Error SyntaxError: Identifier expected, got 'default'. */ diff --git a/ets2panda/test/ast/parser/ets/interface_static_late_initialization_assignment_error.ets b/ets2panda/test/ast/parser/ets/interface_static_late_initialization_assignment_error.ets index 4eb37bbc78..f85d1b3626 100644 --- a/ets2panda/test/ast/parser/ets/interface_static_late_initialization_assignment_error.ets +++ b/ets2panda/test/ast/parser/ets/interface_static_late_initialization_assignment_error.ets @@ -17,4 +17,4 @@ interface A{ static f!:string } -/* @@? 17:5 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 17:5 Error SyntaxError: Identifier expected, got 'static'. */ diff --git a/ets2panda/test/ast/parser/ets/invalid_punctuator_format.ets b/ets2panda/test/ast/parser/ets/invalid_punctuator_format.ets index 2eba0019b6..81f7135a04 100644 --- a/ets2panda/test/ast/parser/ets/invalid_punctuator_format.ets +++ b/ets2panda/test/ast/parser/ets/invalid_punctuator_format.ets @@ -20,8 +20,8 @@ J* @@? /* @@? 17:2 Error SyntaxError: Interface fields must have type annotation. */ /* @@? 17:4 Error SyntaxError: Unexpected token '@@'. */ /* @@? 17:4 Error SyntaxError: Unexpected token, expected ','. */ -/* @@? 17:4 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 17:4 Error SyntaxError: Identifier expected, got 'end of stream'. */ /* @@? 17:6 Error SyntaxError: Identifier expected. */ /* @@? 17:6 Error SyntaxError: Unexpected token, expected ','. */ -/* @@? 17:6 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 17:6 Error SyntaxError: Identifier expected, got 'end of stream'. */ /* @@? 18:1 Error SyntaxError: Identifier expected. */ diff --git a/ets2panda/test/ast/parser/ets/keyword_after_readonly_interface.ets b/ets2panda/test/ast/parser/ets/keyword_after_readonly_interface.ets index 48cf3c4993..70f6ff2691 100644 --- a/ets2panda/test/ast/parser/ets/keyword_after_readonly_interface.ets +++ b/ets2panda/test/ast/parser/ets/keyword_after_readonly_interface.ets @@ -19,9 +19,9 @@ interface A { /* @@? 17:2 Error SyntaxError: Identifier expected. */ /* @@? 17:11 Error SyntaxError: Unexpected token, expected ','. */ -/* @@? 17:11 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 17:11 Error SyntaxError: Identifier expected, got 'static'. */ /* @@? 17:20 Error SyntaxError: Interface fields must have type annotation. */ /* @@? 17:22 Error SyntaxError: Invalid Type. */ /* @@? 17:22 Error SyntaxError: Unexpected token, expected ','. */ -/* @@? 17:22 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 17:22 Error SyntaxError: Identifier expected, got 'number literal'. */ /* @@? 17:24 Error SyntaxError: Identifier expected. */ diff --git a/ets2panda/test/ast/parser/ets/local-interface-member-access-modifier-private1.ets b/ets2panda/test/ast/parser/ets/local-interface-member-access-modifier-private1.ets index 490354a619..f8c9594a0c 100644 --- a/ets2panda/test/ast/parser/ets/local-interface-member-access-modifier-private1.ets +++ b/ets2panda/test/ast/parser/ets/local-interface-member-access-modifier-private1.ets @@ -23,3 +23,4 @@ function foo() /* @@@ label1 Error SyntaxError: Illegal start of INTERFACE expression. */ /* @@@ label2 Error SyntaxError: Local class or interface declaration members can not have access modifies. */ +/* @@@ label2 Error SyntaxError: Identifier expected, got 'private'. */ diff --git a/ets2panda/test/ast/parser/ets/local-interface-member-access-modifier-private2.ets b/ets2panda/test/ast/parser/ets/local-interface-member-access-modifier-private2.ets index 7f76e7b990..160115d07b 100644 --- a/ets2panda/test/ast/parser/ets/local-interface-member-access-modifier-private2.ets +++ b/ets2panda/test/ast/parser/ets/local-interface-member-access-modifier-private2.ets @@ -22,5 +22,5 @@ function foo() } /* @@@ label1 Error SyntaxError: Illegal start of INTERFACE expression. */ -/* @@@ label2 Error SyntaxError: Local class or interface declaration members can not have access modifies. */ -/* @@@ label3 Error SyntaxError: Private interface methods must have body. */ +/* @@@ label2 Error SyntaxError: Local class or interface declaration members can not have access modifies. */ +/* @@@ label3 Error SyntaxError: Private interface methods must have body. */ diff --git a/ets2panda/test/ast/parser/ets/local-interface-member-access-modifier-protected1.ets b/ets2panda/test/ast/parser/ets/local-interface-member-access-modifier-protected1.ets index af6da8fe3b..1444898726 100644 --- a/ets2panda/test/ast/parser/ets/local-interface-member-access-modifier-protected1.ets +++ b/ets2panda/test/ast/parser/ets/local-interface-member-access-modifier-protected1.ets @@ -22,4 +22,4 @@ function foo() } /* @@@ label1 Error SyntaxError: Illegal start of INTERFACE expression. */ -/* @@@ label2 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@@ label2 Error SyntaxError: Identifier expected, got 'protected'. */ diff --git a/ets2panda/test/ast/parser/ets/local_enum.ets b/ets2panda/test/ast/parser/ets/local_enum.ets index 73d642975b..d39f52acf4 100644 --- a/ets2panda/test/ast/parser/ets/local_enum.ets +++ b/ets2panda/test/ast/parser/ets/local_enum.ets @@ -42,7 +42,7 @@ interface I{ /* @@? 24:5 Error SyntaxError: Illegal start of ENUM expression. */ /* @@? 29:3 Error SyntaxError: Unexpected token. A constructor, method, accessor, or property was expected. */ /* @@? 32:5 Error SyntaxError: Illegal start of ENUM expression. */ -/* @@? 37:4 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 37:4 Error SyntaxError: Identifier expected, got 'enum'. */ /* @@? 37:11 Error SyntaxError: Interface fields must have type annotation. */ /* @@? 37:12 Error TypeError: Cannot find type 'E1'. */ /* @@? 38:1 Error SyntaxError: Unexpected token '}'. */ diff --git a/ets2panda/test/ast/parser/ets/local_type_alias.ets b/ets2panda/test/ast/parser/ets/local_type_alias.ets index 9060686ac9..9c22106c8c 100644 --- a/ets2panda/test/ast/parser/ets/local_type_alias.ets +++ b/ets2panda/test/ast/parser/ets/local_type_alias.ets @@ -48,5 +48,5 @@ interface I{ /* @@? 39:9 Error TypeError: Cannot find type 'a'. */ /* @@? 39:11 Error SyntaxError: Interface member initialization is prohibited. */ /* @@? 39:13 Error SyntaxError: Unexpected token, expected ','. */ -/* @@? 39:13 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 39:13 Error SyntaxError: Identifier expected, got 'identification literal'. */ /* @@? 39:14 Error SyntaxError: Identifier expected. */ diff --git a/ets2panda/test/ast/parser/ets/overloaded_method_as_value_neg.ets b/ets2panda/test/ast/parser/ets/overloaded_method_as_value_neg.ets index 1f80043685..e13784c78f 100644 --- a/ets2panda/test/ast/parser/ets/overloaded_method_as_value_neg.ets +++ b/ets2panda/test/ast/parser/ets/overloaded_method_as_value_neg.ets @@ -21,9 +21,9 @@ interface"actual : " + actual.result[i] /* @@? 16:30 Error SyntaxError: Interface fields must have type annotation. */ /* @@? 16:38 Error SyntaxError: Unexpected token, expected ']'. */ /* @@? 16:38 Error SyntaxError: Unexpected token, expected ','. */ -/* @@? 16:38 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 16:38 Error SyntaxError: Identifier expected, got 'identification literal'. */ /* @@? 16:39 Error SyntaxError: Identifier expected. */ /* @@? 16:39 Error SyntaxError: Unexpected token, expected ','. */ -/* @@? 16:39 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 16:39 Error SyntaxError: Identifier expected, got 'end of stream'. */ /* @@? 30:1 Error SyntaxError: Identifier expected. */ /* @@? 30:1 Error SyntaxError: Unexpected token, expected '}'. */ diff --git a/ets2panda/test/ast/parser/ets/struct_in_interface.ets b/ets2panda/test/ast/parser/ets/struct_in_interface.ets index 1d6aafc6bf..60f3efa82e 100644 --- a/ets2panda/test/ast/parser/ets/struct_in_interface.ets +++ b/ets2panda/test/ast/parser/ets/struct_in_interface.ets @@ -22,12 +22,12 @@ interface A { /* @@? 17:16 Error SyntaxError: Interface member initialization is prohibited. */ /* @@? 17:18 Error SyntaxError: Unexpected token, expected ','. */ -/* @@? 17:18 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 17:18 Error SyntaxError: Identifier expected, got 'string literal'. */ /* @@? 18:12 Error TypeError: Cannot find type 'B'. */ /* @@? 18:14 Error SyntaxError: Unexpected token, expected ','. */ -/* @@? 18:14 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 18:14 Error SyntaxError: Identifier expected, got 'end of stream'. */ /* @@? 19:20 Error SyntaxError: Interface member initialization is prohibited. */ /* @@? 19:22 Error SyntaxError: Unexpected token, expected ','. */ -/* @@? 19:22 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@? 19:22 Error SyntaxError: Identifier expected, got 'string literal'. */ /* @@? 20:5 Error SyntaxError: Identifier expected. */ /* @@? 21:1 Error SyntaxError: Unexpected token '}'. */ diff --git a/ets2panda/test/ast/parser/ets/user_defined_25.ets b/ets2panda/test/ast/parser/ets/user_defined_25.ets index a51079cba2..9f7ad7798d 100644 --- a/ets2panda/test/ast/parser/ets/user_defined_25.ets +++ b/ets2panda/test/ast/parser/ets/user_defined_25.ets @@ -20,5 +20,5 @@ interface /* @@ label1 */type { /* @@@ label1 Error SyntaxError: Cannot be used as user-defined type. */ /* @@@ label2 Error SyntaxError: Interface member initialization is prohibited. */ /* @@@ label3 Error SyntaxError: Unexpected token, expected ','. */ -/* @@? 17:48 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@@ label3 Error SyntaxError: Identifier expected, got 'number literal'. */ /* @@@ label4 Error SyntaxError: Identifier expected. */ diff --git a/ets2panda/test/ast/parser/ets/user_defined_7.ets b/ets2panda/test/ast/parser/ets/user_defined_7.ets index 5b9519508f..fbd4aae280 100644 --- a/ets2panda/test/ast/parser/ets/user_defined_7.ets +++ b/ets2panda/test/ast/parser/ets/user_defined_7.ets @@ -20,5 +20,5 @@ interface /* @@ label1 */double { /* @@@ label1 Error SyntaxError: double is a predefined type, cannot be used as an identifier */ /* @@@ label2 Error SyntaxError: Interface member initialization is prohibited. */ /* @@@ label3 Error SyntaxError: Unexpected token, expected ','. */ -/* @@? 17:51 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@@ label3 Error SyntaxError: Identifier expected, got 'string literal'. */ /* @@@ label4 Error SyntaxError: Identifier expected. */ diff --git a/ets2panda/util/diagnostic/syntax.yaml b/ets2panda/util/diagnostic/syntax.yaml index 7027b66d7a..ceffaec5b1 100644 --- a/ets2panda/util/diagnostic/syntax.yaml +++ b/ets2panda/util/diagnostic/syntax.yaml @@ -1235,10 +1235,6 @@ syntax: id: 231 message: "Unexpected token '{}', expected 'case' or 'default'." -- name: UNEXPECTED_TOKEN_PRIVATE_ID - id: 124 - message: "Unexpected token, expected 'private' or identifier." - - name: UNEXPECTED_TOKEN_STRING_LITERAL id: 151 message: "Unexpected token, expected string literal." @@ -1317,6 +1313,7 @@ graveyard: - 109 - 110 - 123 +- 124 - 139 - 142 - 152 -- Gitee