From 5608e0f1de84bfee3d293d48f0ae8a8740dff9ad Mon Sep 17 00:00:00 2001 From: Peter Pronai Date: Wed, 28 May 2025 11:38:26 +0000 Subject: [PATCH 1/3] Improve errors for ExpectIdentifier Literals and reserved keywords now result in more helpful errors. Fixes #24542 internal issue. Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICB8X7 Testing: ast, parser, astchecker Change-Id: I7ec5c7b534f1aef2df8539d0696a2e1e0add651f Signed-off-by: Peter Pronai --- ets2panda/parser/parserImpl.cpp | 5 +++++ .../import_chain_with_errors/import_1.ets | 1 + .../import_chain_with_errors/master_file.ets | 1 + .../keywords/issue26215_restricted_super.ets | 1 + .../compiler/ets/math_const_as_identifier.ets | 1 + .../ets/FixedArray/MultipleParserErrors.ets | 5 ++++- .../test/ast/parser/ets/InvalidParserImpl.ets | 1 + .../ast/parser/ets/MultipleClassErrors.ets | 3 ++- .../ast/parser/ets/MultipleParserErrors.ets | 5 ++++- .../annotationDecl_with_innerclass.ets | 1 + .../parser/ets/interface_parser_error_1.ets | 3 ++- .../ets/overloaded_method_as_value_neg.ets | 19 ++++++++++--------- .../test/ast/parser/ets/user_defined_5.ets | 1 + .../test/ast/parser/ets/user_defined_7.ets | 1 + .../test/ast/parser/js/this-expression.js | 1 + .../test/ast/parser/ts/test-interface2.ts | 1 + ets2panda/util/diagnostic/syntax.yaml | 8 ++++++++ 17 files changed, 45 insertions(+), 13 deletions(-) diff --git a/ets2panda/parser/parserImpl.cpp b/ets2panda/parser/parserImpl.cpp index ade0b8337b..4f66296e62 100644 --- a/ets2panda/parser/parserImpl.cpp +++ b/ets2panda/parser/parserImpl.cpp @@ -1267,6 +1267,11 @@ ir::Identifier *ParserImpl::ExpectIdentifier([[maybe_unused]] bool isReference, if ((options & TypeAnnotationParsingOptions::REPORT_ERROR) == 0) { return nullptr; } + if (token.IsLiteral()) { + LogError(diagnostic::LITERAL_VALUE_IDENT, {token.ToString()}, tokenStart); + } else if (token.IsKeyword()) { + LogError(diagnostic::HARD_KEYWORD_IDENT, {token.ToString()}, tokenStart); + } LogError(diagnostic::IDENTIFIER_EXPECTED_HERE, {TokenToString(tokenType)}, tokenStart); lexer_->NextToken(); return AllocBrokenExpression(tokenStart); diff --git a/ets2panda/test/ast/compiler/ets/import_tests/import_chain_with_errors/import_1.ets b/ets2panda/test/ast/compiler/ets/import_tests/import_chain_with_errors/import_1.ets index 22afeef200..fbf91a5f6d 100644 --- a/ets2panda/test/ast/compiler/ets/import_tests/import_chain_with_errors/import_1.ets +++ b/ets2panda/test/ast/compiler/ets/import_tests/import_chain_with_errors/import_1.ets @@ -26,6 +26,7 @@ let 1: number // First level import with both types of error /* @@? import_1.ets:21:17 Error TypeError: Type 'Int' cannot be assigned to type 'String' */ /* @@? import_1.ets:24:5 Error SyntaxError: Identifier expected, got 'number literal'. */ +/* @@? import_1.ets:24:5 Error SyntaxError: Number, string or computed value property name '1' is not allowed, use classes to access data by property names that are identifiers */ // Second level import import with both types of error /* @@? import_2.ets:17:17 Error TypeError: Type 'Int' cannot be assigned to type 'String' */ diff --git a/ets2panda/test/ast/compiler/ets/import_tests/import_chain_with_errors/master_file.ets b/ets2panda/test/ast/compiler/ets/import_tests/import_chain_with_errors/master_file.ets index fd416a1cde..c7b79fc31d 100644 --- a/ets2panda/test/ast/compiler/ets/import_tests/import_chain_with_errors/master_file.ets +++ b/ets2panda/test/ast/compiler/ets/import_tests/import_chain_with_errors/master_file.ets @@ -20,6 +20,7 @@ let b = new B(10); // First level import with both types of error /* @@? import_1.ets:21:17 Error TypeError: Type 'Int' cannot be assigned to type 'String' */ /* @@? import_1.ets:24:5 Error SyntaxError: Identifier expected, got 'number literal'. */ +/* @@? import_1.ets:24:5 Error SyntaxError: Number, string or computed value property name '1' is not allowed, use classes to access data by property names that are identifiers */ // Second level import import with both types of error /* @@? import_2.ets:17:17 Error TypeError: Type 'Int' cannot be assigned to type 'String' */ diff --git a/ets2panda/test/ast/compiler/ets/keywords/issue26215_restricted_super.ets b/ets2panda/test/ast/compiler/ets/keywords/issue26215_restricted_super.ets index fb422ff9cc..a12fa1c5d2 100644 --- a/ets2panda/test/ast/compiler/ets/keywords/issue26215_restricted_super.ets +++ b/ets2panda/test/ast/compiler/ets/keywords/issue26215_restricted_super.ets @@ -17,4 +17,5 @@ declare namespace super { } +/* @@? 16:19 Error SyntaxError: Hard keyword 'super' cannot be used as identifier */ /* @@? 16:19 Error SyntaxError: Identifier expected, got 'super'. */ diff --git a/ets2panda/test/ast/compiler/ets/math_const_as_identifier.ets b/ets2panda/test/ast/compiler/ets/math_const_as_identifier.ets index 731f743e07..ef222fcc9f 100644 --- a/ets2panda/test/ast/compiler/ets/math_const_as_identifier.ets +++ b/ets2panda/test/ast/compiler/ets/math_const_as_identifier.ets @@ -26,5 +26,6 @@ function foo1() { /* @@? 21:9 Error TypeError: Variable 'NaN' has already been declared. */ /* @@? 22:9 Error TypeError: Variable 'Infinity' has already been declared. */ /* @@? 22:20 Error TypeError: Unresolved reference test */ +/* @@? 23:9 Error SyntaxError: Hard keyword 'undefined' cannot be used as identifier */ /* @@? 23:9 Error SyntaxError: Identifier expected, got 'undefined'. */ /* @@? 24:1 Error SyntaxError: Variable must be initialized or it's type must be declared. */ diff --git a/ets2panda/test/ast/parser/ets/FixedArray/MultipleParserErrors.ets b/ets2panda/test/ast/parser/ets/FixedArray/MultipleParserErrors.ets index eead004100..bfd2a41f7c 100644 --- a/ets2panda/test/ast/parser/ets/FixedArray/MultipleParserErrors.ets +++ b/ets2panda/test/ast/parser/ets/FixedArray/MultipleParserErrors.ets @@ -275,10 +275,13 @@ function main(): void { /* @@? 157:16 Error TypeError: A is abstract therefore cannot be instantiated. */ /* @@? 158:26 Error TypeError: Property 'getInner' does not exist on type 'A' */ /* @@? 161:9 Error SyntaxError: Identifier expected, got 'let'. */ +/* @@? 161:9 Error SyntaxError: Hard keyword 'let' cannot be used as identifier */ +/* @@? 162:9 Error SyntaxError: Hard keyword 'const' cannot be used as identifier */ /* @@? 162:9 Error SyntaxError: Identifier expected, got 'const'. */ /* @@? 163:9 Error SyntaxError: Identifier expected, got 'new'. */ +/* @@? 163:9 Error SyntaxError: Hard keyword 'new' cannot be used as identifier */ /* @@? 164:5 Error TypeError: This expression is not callable. */ /* @@? 165:5 Error TypeError: This expression is not callable. */ /* @@? 166:5 Error TypeError: Expected 1 arguments, got 0. */ /* @@? 166:5 Error TypeError: No matching call signature */ -/* @@? 285:1 Error SyntaxError: Expected '}', got 'end of stream'. */ +/* @@? 288:1 Error SyntaxError: Expected '}', got 'end of stream'. */ diff --git a/ets2panda/test/ast/parser/ets/InvalidParserImpl.ets b/ets2panda/test/ast/parser/ets/InvalidParserImpl.ets index f1a1bac935..feca6d13ff 100644 --- a/ets2panda/test/ast/parser/ets/InvalidParserImpl.ets +++ b/ets2panda/test/ast/parser/ets/InvalidParserImpl.ets @@ -26,4 +26,5 @@ class int {} /* @@? 18:5 Error SyntaxError: Getter must not have formal parameters. */ /* @@? 19:1 Error SyntaxError: Setter must have exactly one formal parameter. */ /* @@? 23:7 Error SyntaxError: Cannot be used as user-defined type. */ +/* @@? 23:7 Error SyntaxError: Hard keyword 'int' cannot be used as identifier */ /* @@? 23:7 Error SyntaxError: Identifier expected, got 'int'. */ diff --git a/ets2panda/test/ast/parser/ets/MultipleClassErrors.ets b/ets2panda/test/ast/parser/ets/MultipleClassErrors.ets index 216d6b70d7..2eca08c7dc 100644 --- a/ets2panda/test/ast/parser/ets/MultipleClassErrors.ets +++ b/ets2panda/test/ast/parser/ets/MultipleClassErrors.ets @@ -33,7 +33,8 @@ class /* @@ label4 */{/* @@ label5 */} /* @@? 21:20 Error SyntaxError: Unexpected token 'let'. */ /* @@? 22:20 Error SyntaxError: Unexpected token 'let'. */ /* @@? 24:17 Error TypeError: Type '"abc"' cannot be assigned to type 'Double' */ +/* @@? 28:22 Error SyntaxError: Number, string or computed value property name '77' is not allowed, use classes to access data by property names that are identifiers */ /* @@? 28:22 Error SyntaxError: Identifier expected, got 'number literal'. */ /* @@? 30:22 Error SyntaxError: Identifier expected, got '{'. */ /* @@? 30:38 Error SyntaxError: Expected '{', got '}'. */ -/* @@? 40:1 Error SyntaxError: Expected '}', got 'end of stream'. */ +/* @@? 41:1 Error SyntaxError: Expected '}', got 'end of stream'. */ diff --git a/ets2panda/test/ast/parser/ets/MultipleParserErrors.ets b/ets2panda/test/ast/parser/ets/MultipleParserErrors.ets index 9358e02dd9..f90392bf93 100644 --- a/ets2panda/test/ast/parser/ets/MultipleParserErrors.ets +++ b/ets2panda/test/ast/parser/ets/MultipleParserErrors.ets @@ -273,10 +273,13 @@ function main(): void { /* @@? 157:16 Error TypeError: A is abstract therefore cannot be instantiated. */ /* @@? 158:26 Error TypeError: Property 'getInner' does not exist on type 'A' */ /* @@? 161:9 Error SyntaxError: Identifier expected, got 'let'. */ +/* @@? 161:9 Error SyntaxError: Hard keyword 'let' cannot be used as identifier */ +/* @@? 162:9 Error SyntaxError: Hard keyword 'const' cannot be used as identifier */ /* @@? 162:9 Error SyntaxError: Identifier expected, got 'const'. */ +/* @@? 163:9 Error SyntaxError: Hard keyword 'new' cannot be used as identifier */ /* @@? 163:9 Error SyntaxError: Identifier expected, got 'new'. */ /* @@? 164:5 Error TypeError: This expression is not callable. */ /* @@? 165:5 Error TypeError: This expression is not callable. */ /* @@? 166:5 Error TypeError: Expected 1 arguments, got 0. */ /* @@? 166:5 Error TypeError: No matching call signature */ -/* @@? 283:1 Error SyntaxError: Expected '}', got 'end of stream'. */ +/* @@? 286:1 Error SyntaxError: Expected '}', got 'end of stream'. */ diff --git a/ets2panda/test/ast/parser/ets/annotations_tests/annotationDecl_with_innerclass.ets b/ets2panda/test/ast/parser/ets/annotations_tests/annotationDecl_with_innerclass.ets index 79ef906623..02ed066c23 100644 --- a/ets2panda/test/ast/parser/ets/annotations_tests/annotationDecl_with_innerclass.ets +++ b/ets2panda/test/ast/parser/ets/annotations_tests/annotationDecl_with_innerclass.ets @@ -17,6 +17,7 @@ class A{} } +/* @@? 17:5 Error SyntaxError: Hard keyword 'class' cannot be used as identifier */ /* @@? 17:5 Error SyntaxError: Identifier expected, got 'class'. */ /* @@? 17:12 Error SyntaxError: Missing type annotation for property 'A'. */ /* @@? 17:12 Error SyntaxError: Identifier expected, got '{'. */ 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 afa196d8f3..05540be90d 100644 --- a/ets2panda/test/ast/parser/ets/interface_parser_error_1.ets +++ b/ets2panda/test/ast/parser/ets/interface_parser_error_1.ets @@ -59,9 +59,10 @@ function mdin() { let a = new A(); /* @@? 26:19 Error SyntaxError: Unexpected token, expected an identifier. */ /* @@? 27:5 Error SyntaxError: Unexpected token 'A'. */ /* @@? 27:7 Error SyntaxError: Unexpected token '{'. */ +/* @@? 28:5 Error SyntaxError: Hard keyword 'constructor' cannot be used as identifier */ /* @@? 28:5 Error SyntaxError: Identifier expected, got 'constructor'. */ /* @@? 28:19 Error SyntaxError: Annotations are not allowed on this type of declaration. */ /* @@? 29:18 Error SyntaxError: Unexpected token, expected an identifier. */ /* @@? 31:2 Error SyntaxError: Unexpected token '*'. */ /* @@? 32:1 Error SyntaxError: Nested functions are not allowed. */ -/* @@? 68:1 Error SyntaxError: Expected '}', got 'end of stream'. */ +/* @@? 69:1 Error SyntaxError: Expected '}', got 'end of stream'. */ 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 2624a849c2..1f80043685 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 @@ -13,16 +13,17 @@ * limitations under the License. */ -interface"actual : " + actual.result[i] +interface"actual : " + actual.result[i] +/* @@? 16:10 Error SyntaxError: Number, string or computed value property name 'actual : ' is not allowed, use classes to access data by property names that are identifiers */ /* @@? 16:10 Error SyntaxError: Identifier expected, got 'string literal'. */ -/* @@? 16:23 Error SyntaxError: Unexpected token, expected '{'. */ -/* @@? 16:31 Error SyntaxError: Interface fields must have type annotation. */ -/* @@? 16:39 Error SyntaxError: Unexpected token, expected ']'. */ +/* @@? 16:22 Error SyntaxError: Unexpected token, expected '{'. */ +/* @@? 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:39 Error SyntaxError: Identifier expected. */ /* @@? 16:39 Error SyntaxError: Unexpected token, expected ','. */ /* @@? 16:39 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ -/* @@? 16:40 Error SyntaxError: Identifier expected. */ -/* @@? 16:40 Error SyntaxError: Unexpected token, expected ','. */ -/* @@? 16:40 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ -/* @@? 28:67 Error SyntaxError: Identifier expected. */ -/* @@? 28:67 Error SyntaxError: Unexpected token, expected '}'. */ \ No newline at end of file +/* @@? 30:1 Error SyntaxError: Identifier expected. */ +/* @@? 30:1 Error SyntaxError: Unexpected token, expected '}'. */ diff --git a/ets2panda/test/ast/parser/ets/user_defined_5.ets b/ets2panda/test/ast/parser/ets/user_defined_5.ets index bdf44a3c52..5407609861 100644 --- a/ets2panda/test/ast/parser/ets/user_defined_5.ets +++ b/ets2panda/test/ast/parser/ets/user_defined_5.ets @@ -19,3 +19,4 @@ enum /* @@ label */double { /* @@@ label Error SyntaxError: Cannot be used as user-defined type. */ /* @@@ label Error SyntaxError: Identifier expected, got 'double'. */ +/* @@@ label Error SyntaxError: Hard keyword 'double' cannot be used as identifier */ diff --git a/ets2panda/test/ast/parser/ets/user_defined_7.ets b/ets2panda/test/ast/parser/ets/user_defined_7.ets index 67c6eec095..587457df03 100644 --- a/ets2panda/test/ast/parser/ets/user_defined_7.ets +++ b/ets2panda/test/ast/parser/ets/user_defined_7.ets @@ -19,6 +19,7 @@ interface /* @@ label1 */double { /* @@@ label1 Error SyntaxError: Cannot be used as user-defined type. */ /* @@@ label1 Error SyntaxError: Identifier expected, got 'double'. */ +/* @@@ label1 Error SyntaxError: Hard keyword 'double' cannot be used as 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. */ diff --git a/ets2panda/test/ast/parser/js/this-expression.js b/ets2panda/test/ast/parser/js/this-expression.js index c0245f8531..884e651960 100644 --- a/ets2panda/test/ast/parser/js/this-expression.js +++ b/ets2panda/test/ast/parser/js/this-expression.js @@ -17,3 +17,4 @@ this./* @@ label */"foo"; /* @@@ label Error SyntaxError: Identifier expected, got 'string literal'. */ +/* @@@ label Error SyntaxError: Number, string or computed value property name 'foo' is not allowed, use classes to access data by property names that are identifiers */ diff --git a/ets2panda/test/ast/parser/ts/test-interface2.ts b/ets2panda/test/ast/parser/ts/test-interface2.ts index 95377c9927..9e3c4b26f6 100644 --- a/ets2panda/test/ast/parser/ts/test-interface2.ts +++ b/ets2panda/test/ast/parser/ts/test-interface2.ts @@ -16,3 +16,4 @@ interface /* @@ label */5 { } /* @@@ label Error SyntaxError: Identifier expected, got 'number literal'. */ +/* @@@ label Error SyntaxError: Number, string or computed value property name '5' is not allowed, use classes to access data by property names that are identifiers */ diff --git a/ets2panda/util/diagnostic/syntax.yaml b/ets2panda/util/diagnostic/syntax.yaml index 8a1a9bafa9..738206ec7e 100644 --- a/ets2panda/util/diagnostic/syntax.yaml +++ b/ets2panda/util/diagnostic/syntax.yaml @@ -1267,3 +1267,11 @@ syntax: - name: GENERATOR_FUNCTION id: 314 message: "Generator functions are not supported, please use async/await mechanism for multitasking" + +- name: LITERAL_VALUE_IDENT + id: 315 + message: "Number, string or computed value property name '{}' is not allowed, use classes to access data by property names that are identifiers" + +- name: HARD_KEYWORD_IDENT + id: 316 + message: "Hard keyword '{}' cannot be used as identifier" -- Gitee From e194453ce4544a1dddd9b1fcebe52f7dd6522aa0 Mon Sep 17 00:00:00 2001 From: Boglarka Date: Thu, 5 Jun 2025 15:03:49 +0200 Subject: [PATCH 2/3] Add error for using namespaces as object Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICCJ7D Reason: Using namespaces or classes as object is invalid Description: Modified error masseges Change-Id: I7ec5c7b534f1aef2df8539d0696a2e1e0add651f Signed-off-by: Haag Boglarka --- ets2panda/checker/ets/helpers.cpp | 6 ++++-- .../test/ast/compiler/ets/FixedArray/tuple_types_9_neg.ets | 2 +- .../compiler/ets/namespace_tests/namespace_as_type11.ets | 2 +- ets2panda/test/ast/compiler/ets/static_index_function1.ets | 2 +- ets2panda/test/ast/compiler/ets/static_index_function2.ets | 2 +- .../ets/type_error_processing/not_constructible_types.ets | 2 +- .../annotations_tests/annotationDecl_bad_initializer01.ets | 2 +- .../ets/annotations_tests/annotationUsage_bad_param01.ets | 2 +- .../annotationUsage_bad_param_for_classproperty.ets | 4 ++-- .../annotationUsage_bad_param_for_function_param.ets | 2 +- .../annotationUsage_bad_param_for_global_variable_decl.ets | 2 +- .../annotationUsage_bad_param_for_interface.ets | 2 +- .../annotationUsage_bad_param_for_interfacemethod.ets | 2 +- .../annotationUsage_bad_param_for_interfaceproperty.ets | 2 +- .../annotationUsage_bad_param_for_local_variable_decl.ets | 2 +- .../annotationUsage_bad_param_for_type_alias.ets | 4 ++-- ets2panda/test/ast/parser/ets/async_function_bad.ets | 2 +- ets2panda/test/ast/parser/ets/type_references.ets | 2 +- ets2panda/test/ast/parser/ets/unexpected_token_62.ets | 4 ++-- ets2panda/test/ast/parser/ets/wrong_context_class_1.ets | 2 +- ets2panda/test/ast/parser/ets/wrong_context_class_2.ets | 2 +- ets2panda/test/ast/parser/ets/wrong_context_class_3.ets | 2 +- ets2panda/test/ast/parser/ets/wrong_context_class_4.ets | 2 +- .../ets/abstractNewClassInstanceExpression-expected.txt | 2 +- ets2panda/util/diagnostic/syntax.yaml | 4 ++++ 25 files changed, 34 insertions(+), 28 deletions(-) diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index 2d284a52d0..8be037eadd 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -99,11 +99,13 @@ void ETSChecker::WrongContextErrorClassifyByType(ir::Identifier *ident) varbinder::VariableFlags::TYPE))) { case varbinder::VariableFlags::CLASS: identCategoryName = "Class"; - break; + LogError(diagnostic::NOT_AS_OBJECT, {identCategoryName}, ident->Start()); + return; case varbinder::VariableFlags::NAMESPACE: identCategoryName = "Namespace"; - break; + LogError(diagnostic::NOT_AS_OBJECT, {identCategoryName}, ident->Start()); + return; case varbinder::VariableFlags::METHOD: identCategoryName = "Function"; diff --git a/ets2panda/test/ast/compiler/ets/FixedArray/tuple_types_9_neg.ets b/ets2panda/test/ast/compiler/ets/FixedArray/tuple_types_9_neg.ets index 978f7ce86d..baddef4e13 100644 --- a/ets2panda/test/ast/compiler/ets/FixedArray/tuple_types_9_neg.ets +++ b/ets2panda/test/ast/compiler/ets/FixedArray/tuple_types_9_neg.ets @@ -24,6 +24,6 @@ function main(): void { /* @@? 18:40 Error SyntaxError: Unexpected token, expected ',' or ']'. */ /* @@? 18:40 Error SyntaxError: Unexpected token '>'. */ /* @@? 18:43 Error SyntaxError: Unexpected token 'Int'. */ -/* @@? 18:43 Error TypeError: Class name 'Int' used in the wrong context */ +/* @@? 18:43 Error SyntaxError: Class cannot be used as object. */ /* @@? 18:43 Error TypeError: Bad operand type, the types of the operands must be numeric, same enumeration, or boolean type. */ /* @@? 18:47 Error SyntaxError: Unexpected token ']'. */ diff --git a/ets2panda/test/ast/compiler/ets/namespace_tests/namespace_as_type11.ets b/ets2panda/test/ast/compiler/ets/namespace_tests/namespace_as_type11.ets index b9f5b38405..eb120df6c8 100644 --- a/ets2panda/test/ast/compiler/ets/namespace_tests/namespace_as_type11.ets +++ b/ets2panda/test/ast/compiler/ets/namespace_tests/namespace_as_type11.ets @@ -18,4 +18,4 @@ namespace MySpace { let a = /* @@ label */MySpace -/* @@@ label Error TypeError: Namespace name 'MySpace' used in the wrong context */ +/* @@@ label Error SyntaxError: Namespace cannot be used as object. */ diff --git a/ets2panda/test/ast/compiler/ets/static_index_function1.ets b/ets2panda/test/ast/compiler/ets/static_index_function1.ets index a341c997c9..36c1a7ebd5 100644 --- a/ets2panda/test/ast/compiler/ets/static_index_function1.ets +++ b/ets2panda/test/ast/compiler/ets/static_index_function1.ets @@ -29,5 +29,5 @@ function main() { /* @@@ label Error TypeError: '$_get' is a static property of 'A' */ /* @@@ label1 Error TypeError: '$_get' is a static property of 'A' */ -/* @@@ label2 Error TypeError: Class name 'A' used in the wrong context */ +/* @@@ label2 Error SyntaxError: Class cannot be used as object. */ /* @@@ label3 Error TypeError: '$_get' is a static property of 'A' */ diff --git a/ets2panda/test/ast/compiler/ets/static_index_function2.ets b/ets2panda/test/ast/compiler/ets/static_index_function2.ets index 9659ccec52..c6ae1e214f 100644 --- a/ets2panda/test/ast/compiler/ets/static_index_function2.ets +++ b/ets2panda/test/ast/compiler/ets/static_index_function2.ets @@ -27,5 +27,5 @@ function main(): int { } /* @@@ label Error TypeError: '$_set' is a static property of 'A' */ -/* @@@ label1 Error TypeError: Class name 'A' used in the wrong context */ +/* @@@ label1 Error SyntaxError: Class cannot be used as object. */ /* @@@ label2 Error TypeError: '$_set' is a static property of 'A' */ diff --git a/ets2panda/test/ast/compiler/ets/type_error_processing/not_constructible_types.ets b/ets2panda/test/ast/compiler/ets/type_error_processing/not_constructible_types.ets index 05eb89b3eb..4341a3928c 100644 --- a/ets2panda/test/ast/compiler/ets/type_error_processing/not_constructible_types.ets +++ b/ets2panda/test/ast/compiler/ets/type_error_processing/not_constructible_types.ets @@ -35,5 +35,5 @@ WeakSet [12] = new undefined() /* @@? 20:1 Error TypeError: This expression is not constructible. */ /* @@? 23:1 Error TypeError: The union type is not constructible. */ /* @@? 26:1 Error TypeError: Indexed signatures are not allowed. Use arrays instead! */ -/* @@? 26:1 Error TypeError: Class name 'WeakSet' used in the wrong context */ +/* @@? 26:1 Error SyntaxError: Class cannot be used as object. */ /* @@? 26:16 Error TypeError: Type 'undefined' is not constructible. */ diff --git a/ets2panda/test/ast/parser/ets/annotations_tests/annotationDecl_bad_initializer01.ets b/ets2panda/test/ast/parser/ets/annotations_tests/annotationDecl_bad_initializer01.ets index c91e54e8e1..1c44ded693 100644 --- a/ets2panda/test/ast/parser/ets/annotations_tests/annotationDecl_bad_initializer01.ets +++ b/ets2panda/test/ast/parser/ets/annotations_tests/annotationDecl_bad_initializer01.ets @@ -20,6 +20,6 @@ class A{} } -/* @@@ label Error TypeError: Class name 'A' used in the wrong context */ +/* @@@ label Error SyntaxError: Class cannot be used as object. */ /* @@@ label Error TypeError: Type 'A' cannot be assigned to type 'String' */ /* @@@ label Error TypeError: Invalid value for annotation field, expected a constant literal. */ diff --git a/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_bad_param01.ets b/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_bad_param01.ets index 291e9fc476..2fb3feaa78 100644 --- a/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_bad_param01.ets +++ b/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_bad_param01.ets @@ -23,6 +23,6 @@ class A{} class B{} -/* @@@ label Error TypeError: Class name 'A' used in the wrong context */ +/* @@@ label Error SyntaxError: Class cannot be used as object. */ /* @@@ label Error TypeError: Type 'A' cannot be assigned to type 'String' */ /* @@@ label Error TypeError: Invalid value for annotation field, expected a constant literal. */ diff --git a/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_bad_param_for_classproperty.ets b/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_bad_param_for_classproperty.ets index 6bda66d089..389af848c7 100644 --- a/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_bad_param_for_classproperty.ets +++ b/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_bad_param_for_classproperty.ets @@ -28,9 +28,9 @@ class B{ } -/* @@@ label1 Error TypeError: Class name 'A' used in the wrong context */ +/* @@@ label1 Error SyntaxError: Class cannot be used as object. */ /* @@@ label1 Error TypeError: Type 'A' cannot be assigned to type 'String' */ /* @@@ label1 Error TypeError: Invalid value for annotation field, expected a constant literal. */ -/* @@@ label2 Error TypeError: Class name 'A' used in the wrong context */ +/* @@@ label2 Error SyntaxError: Class cannot be used as object. */ /* @@@ label2 Error TypeError: Type 'A' cannot be assigned to type 'String' */ /* @@@ label2 Error TypeError: Invalid value for annotation field, expected a constant literal. */ diff --git a/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_bad_param_for_function_param.ets b/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_bad_param_for_function_param.ets index 4b9930aa0d..cf347df6c7 100644 --- a/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_bad_param_for_function_param.ets +++ b/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_bad_param_for_function_param.ets @@ -23,6 +23,6 @@ class A{} function foo(@MyAnno({testProperty1: /* @@ label */A}) x: int) { } -/* @@@ label Error TypeError: Class name 'A' used in the wrong context */ +/* @@@ label Error SyntaxError: Class cannot be used as object. */ /* @@@ label Error TypeError: Type 'A' cannot be assigned to type 'String' */ /* @@@ label Error TypeError: Invalid value for annotation field, expected a constant literal. */ diff --git a/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_bad_param_for_global_variable_decl.ets b/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_bad_param_for_global_variable_decl.ets index 42cc5b89bb..535b365f32 100644 --- a/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_bad_param_for_global_variable_decl.ets +++ b/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_bad_param_for_global_variable_decl.ets @@ -24,6 +24,6 @@ class A{} let x = "abc" -/* @@@ label Error TypeError: Class name 'A' used in the wrong context */ +/* @@@ label Error SyntaxError: Class cannot be used as object. */ /* @@@ label Error TypeError: Type 'A' cannot be assigned to type 'String' */ /* @@@ label Error TypeError: Invalid value for annotation field, expected a constant literal. */ diff --git a/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_bad_param_for_interface.ets b/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_bad_param_for_interface.ets index b05a133e46..d544f882f7 100644 --- a/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_bad_param_for_interface.ets +++ b/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_bad_param_for_interface.ets @@ -25,6 +25,6 @@ interface itf { foo() : string } -/* @@@ label Error TypeError: Class name 'A' used in the wrong context */ +/* @@@ label Error SyntaxError: Class cannot be used as object. */ /* @@@ label Error TypeError: Type 'A' cannot be assigned to type 'String' */ /* @@@ label Error TypeError: Invalid value for annotation field, expected a constant literal. */ diff --git a/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_bad_param_for_interfacemethod.ets b/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_bad_param_for_interfacemethod.ets index 1dc2531c2f..ae609bf8f8 100644 --- a/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_bad_param_for_interfacemethod.ets +++ b/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_bad_param_for_interfacemethod.ets @@ -25,6 +25,6 @@ interface itf { } -/* @@@ label Error TypeError: Class name 'A' used in the wrong context */ +/* @@@ label Error SyntaxError: Class cannot be used as object. */ /* @@@ label Error TypeError: Type 'A' cannot be assigned to type 'String' */ /* @@@ label Error TypeError: Invalid value for annotation field, expected a constant literal. */ diff --git a/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_bad_param_for_interfaceproperty.ets b/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_bad_param_for_interfaceproperty.ets index 87ea5db605..4ce655dabf 100644 --- a/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_bad_param_for_interfaceproperty.ets +++ b/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_bad_param_for_interfaceproperty.ets @@ -25,6 +25,6 @@ interface itf { } -/* @@@ label Error TypeError: Class name 'A' used in the wrong context */ +/* @@@ label Error SyntaxError: Class cannot be used as object. */ /* @@@ label Error TypeError: Type 'A' cannot be assigned to type 'String' */ /* @@@ label Error TypeError: Invalid value for annotation field, expected a constant literal. */ diff --git a/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_bad_param_for_local_variable_decl.ets b/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_bad_param_for_local_variable_decl.ets index bcb548094f..9c65ff8922 100644 --- a/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_bad_param_for_local_variable_decl.ets +++ b/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_bad_param_for_local_variable_decl.ets @@ -26,6 +26,6 @@ function main():void { } -/* @@@ label Error TypeError: Class name 'A' used in the wrong context */ +/* @@@ label Error SyntaxError: Class cannot be used as object. */ /* @@@ label Error TypeError: Type 'A' cannot be assigned to type 'String' */ /* @@@ label Error TypeError: Invalid value for annotation field, expected a constant literal. */ diff --git a/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_bad_param_for_type_alias.ets b/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_bad_param_for_type_alias.ets index 20828eff75..9eb2aa1f06 100644 --- a/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_bad_param_for_type_alias.ets +++ b/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_bad_param_for_type_alias.ets @@ -29,9 +29,9 @@ function main(): void { } -/* @@@ label1 Error TypeError: Class name 'A' used in the wrong context */ +/* @@@ label1 Error SyntaxError: Class cannot be used as object. */ /* @@@ label1 Error TypeError: Type 'A' cannot be assigned to type 'String' */ /* @@@ label1 Error TypeError: Invalid value for annotation field, expected a constant literal. */ -/* @@@ label2 Error TypeError: Class name 'A' used in the wrong context */ +/* @@@ label2 Error SyntaxError: Class cannot be used as object. */ /* @@@ label2 Error TypeError: Type 'A' cannot be assigned to type 'String' */ /* @@@ label2 Error TypeError: Invalid value for annotation field, expected a constant literal. */ diff --git a/ets2panda/test/ast/parser/ets/async_function_bad.ets b/ets2panda/test/ast/parser/ets/async_function_bad.ets index 6b628497f9..b55c2ffaf8 100644 --- a/ets2panda/test/ast/parser/ets/async_function_bad.ets +++ b/ets2panda/test/ast/parser/ets/async_function_bad.ets @@ -25,4 +25,4 @@ async native function foo(): Promise; /* @@? 16:27 Error SyntaxError: Unexpected token ')'. */ /* @@? 16:28 Error SyntaxError: Unexpected token, expected ')'. */ /* @@? 16:30 Error SyntaxError: Unexpected token 'Promise'. */ -/* @@? 16:30 Error TypeError: Class name 'Promise' used in the wrong context */ +/* @@? 16:30 Error SyntaxError: Class cannot be used as object. */ diff --git a/ets2panda/test/ast/parser/ets/type_references.ets b/ets2panda/test/ast/parser/ets/type_references.ets index b689bb2c97..a5db99d97c 100644 --- a/ets2panda/test/ast/parser/ets/type_references.ets +++ b/ets2panda/test/ast/parser/ets/type_references.ets @@ -25,7 +25,7 @@ let y: G<{a:String}, B> // Error /* @@? 19:10 Error SyntaxError: Unexpected token '>'. */ /* @@? 19:11 Error SyntaxError: Unexpected token 'a'. */ /* @@? 19:13 Error SyntaxError: Label must be followed by a loop statement. */ -/* @@? 19:13 Error TypeError: Class name 'String' used in the wrong context */ +/* @@? 19:13 Error SyntaxError: Class cannot be used as object. */ /* @@? 19:19 Error SyntaxError: Unexpected token '}'. */ /* @@? 19:20 Error SyntaxError: Unexpected token ','. */ /* @@? 19:22 Error SyntaxError: Unexpected token 'B'. */ diff --git a/ets2panda/test/ast/parser/ets/unexpected_token_62.ets b/ets2panda/test/ast/parser/ets/unexpected_token_62.ets index b397c9a783..78b6905b98 100644 --- a/ets2panda/test/ast/parser/ets/unexpected_token_62.ets +++ b/ets2panda/test/ast/parser/ets/unexpected_token_62.ets @@ -34,7 +34,7 @@ int = 10 /* @@? 20:1 Error SyntaxError: Unexpected token, expected an identifier. */ /* @@? 20:1 Error TypeError: Unresolved reference nt */ /* @@? 20:10 Error SyntaxError: Unexpected token 'A'. */ -/* @@? 20:10 Error TypeError: Class name 'A' used in the wrong context */ +/* @@? 20:10 Error SyntaxError: Class cannot be used as object. */ /* @@? 20:12 Error SyntaxError: Unexpected token '{'. */ /* @@? 22:11 Error SyntaxError: Unexpected token 'Nu'. */ /* @@? 23:1 Error SyntaxError: Unexpected token, expected an identifier. */ @@ -48,7 +48,7 @@ int = 10 /* @@? 24:21 Error SyntaxError: Label must be followed by a loop statement. */ /* @@? 24:21 Error TypeError: Unresolved reference s */ /* @@? 24:23 Error SyntaxError: Unexpected token 'A'. */ -/* @@? 24:23 Error TypeError: Class name 'A' used in the wrong context */ +/* @@? 24:23 Error SyntaxError: Class cannot be used as object. */ /* @@? 24:25 Error SyntaxError: Unexpected token '{'. */ /* @@? 25:1 Error SyntaxError: Unexpected token 'int'. */ /* @@? 26:1 Error SyntaxError: Unexpected token ')'. */ diff --git a/ets2panda/test/ast/parser/ets/wrong_context_class_1.ets b/ets2panda/test/ast/parser/ets/wrong_context_class_1.ets index ecd46879d0..76848aae0f 100644 --- a/ets2panda/test/ast/parser/ets/wrong_context_class_1.ets +++ b/ets2panda/test/ast/parser/ets/wrong_context_class_1.ets @@ -22,5 +22,5 @@ function main() /* @@ label */a = /* @@ label1 */5 } -/* @@@ label Error TypeError: Class name 'a' used in the wrong context */ +/* @@@ label Error SyntaxError: Class cannot be used as object. */ /* @@@ label1 Error TypeError: Type 'Int' cannot be assigned to type 'a' */ diff --git a/ets2panda/test/ast/parser/ets/wrong_context_class_2.ets b/ets2panda/test/ast/parser/ets/wrong_context_class_2.ets index c0f2c427e8..f26cb6dee6 100644 --- a/ets2panda/test/ast/parser/ets/wrong_context_class_2.ets +++ b/ets2panda/test/ast/parser/ets/wrong_context_class_2.ets @@ -23,5 +23,5 @@ function main() b = a } -/* @@? 23:9 Error TypeError: Class name 'a' used in the wrong context */ +/* @@? 23:9 Error SyntaxError: Class cannot be used as object. */ /* @@? 23:9 Error TypeError: Type 'a' cannot be assigned to type 'Int' */ diff --git a/ets2panda/test/ast/parser/ets/wrong_context_class_3.ets b/ets2panda/test/ast/parser/ets/wrong_context_class_3.ets index d0818058f7..6b54667d9f 100644 --- a/ets2panda/test/ast/parser/ets/wrong_context_class_3.ets +++ b/ets2panda/test/ast/parser/ets/wrong_context_class_3.ets @@ -22,5 +22,5 @@ function main() a++ } -/* @@? 22:5 Error TypeError: Class name 'a' used in the wrong context */ +/* @@? 22:5 Error SyntaxError: Class cannot be used as object. */ /* @@? 22:5 Error TypeError: Bad operand type, the type of the operand must be numeric type. */ diff --git a/ets2panda/test/ast/parser/ets/wrong_context_class_4.ets b/ets2panda/test/ast/parser/ets/wrong_context_class_4.ets index 3af604d858..531f3707e9 100644 --- a/ets2panda/test/ast/parser/ets/wrong_context_class_4.ets +++ b/ets2panda/test/ast/parser/ets/wrong_context_class_4.ets @@ -27,4 +27,4 @@ function main() } /* @@? 26:5 Error TypeError: Indexed signatures are not allowed. Use arrays instead! */ -/* @@? 26:5 Error TypeError: Class name 'a' used in the wrong context */ +/* @@? 26:5 Error SyntaxError: Class cannot be used as object. */ diff --git a/ets2panda/test/compiler/ets/abstractNewClassInstanceExpression-expected.txt b/ets2panda/test/compiler/ets/abstractNewClassInstanceExpression-expected.txt index 7d401ea3ae..c9fa2adc08 100644 --- a/ets2panda/test/compiler/ets/abstractNewClassInstanceExpression-expected.txt +++ b/ets2panda/test/compiler/ets/abstractNewClassInstanceExpression-expected.txt @@ -1297,6 +1297,6 @@ TypeError: A is abstract therefore cannot be instantiated. [abstractNewClassInst SyntaxError: Unexpected token '{'. [abstractNewClassInstanceExpression.ets:26:22] TypeError: Method foo(): void in B not overriding any method [abstractNewClassInstanceExpression.ets:27:21] SyntaxError: Label must be followed by a loop statement. [abstractNewClassInstanceExpression.ets:32:11] -TypeError: Class name 'H' used in the wrong context [abstractNewClassInstanceExpression.ets:32:11] +SyntaxError: Class cannot be used as object. [abstractNewClassInstanceExpression.ets:32:11] SyntaxError: Unexpected token '{'. [abstractNewClassInstanceExpression.ets:32:23] SyntaxError: Unexpected token '}'. [abstractNewClassInstanceExpression.ets:35:1] diff --git a/ets2panda/util/diagnostic/syntax.yaml b/ets2panda/util/diagnostic/syntax.yaml index 738206ec7e..1c6454cf5b 100644 --- a/ets2panda/util/diagnostic/syntax.yaml +++ b/ets2panda/util/diagnostic/syntax.yaml @@ -1275,3 +1275,7 @@ syntax: - name: HARD_KEYWORD_IDENT id: 316 message: "Hard keyword '{}' cannot be used as identifier" + +- name: NOT_AS_OBJECT + id: 318 + message: "{} cannot be used as object." -- Gitee From 044785b6ac33b6da8379b4eb8131aca05369fb34 Mon Sep 17 00:00:00 2001 From: Peter Pronai Date: Wed, 4 Jun 2025 13:38:58 +0000 Subject: [PATCH 3/3] Diagnostics for function expression and params Fixes #24642 internal issue. Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICCNG1 Testing: ast, astchecker, parser Change-Id: I7ec5c7b534f1aef2df8539d0696a2e1e0add651f Signed-off-by: Peter Pronai --- ets2panda/parser/ETSparser.cpp | 10 ++++++++ ets2panda/parser/ETSparserExpressions.cpp | 8 +++++-- .../compiler/ets/invalid_two_functions.ets | 5 ++-- .../keywords/issue26215_restricted_this.ets | 1 + .../test/ast/parser/ets/decl_in_param.ets | 24 +++++++++++++++++++ .../ets/empty_array_map_inference_fail.ets | 5 ++-- ets2panda/util/diagnostic/syntax.yaml | 8 +++++++ 7 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 ets2panda/test/ast/parser/ets/decl_in_param.ets diff --git a/ets2panda/parser/ETSparser.cpp b/ets2panda/parser/ETSparser.cpp index efb296e96b..33176a5cc1 100644 --- a/ets2panda/parser/ETSparser.cpp +++ b/ets2panda/parser/ETSparser.cpp @@ -1590,6 +1590,16 @@ bool ETSParser::IsFixedArrayTypeNode(ir::AstNode *node) ir::Expression *ETSParser::ParseFunctionParameter() { + switch (Lexer()->GetToken().Type()) { + case lexer::TokenType::KEYW_PRIVATE: + case lexer::TokenType::KEYW_PUBLIC: + case lexer::TokenType::KEYW_PROTECTED: + LogError(diagnostic::FIELD_IN_PARAM); + Lexer()->NextToken(); + default: + break; + } + if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_AT) { return ParseFunctionParameterAnnotations(); } diff --git a/ets2panda/parser/ETSparserExpressions.cpp b/ets2panda/parser/ETSparserExpressions.cpp index 7a0cb42540..bff2cbec61 100644 --- a/ets2panda/parser/ETSparserExpressions.cpp +++ b/ets2panda/parser/ETSparserExpressions.cpp @@ -359,9 +359,13 @@ ir::Expression *ETSParser::ParsePrimaryExpression(ExpressionParseFlags flags) } case lexer::TokenType::KEYW_TYPE: { LogError(diagnostic::TYPE_ALIAS_ONLY_TOP_LEVEL); - const auto &rangeToken = Lexer()->GetToken().Loc(); ParseTypeAliasDeclaration(); // Try to parse type alias and drop the result. - return AllocBrokenExpression(rangeToken); + return AllocBrokenExpression(Lexer()->GetToken().Loc()); + } + case lexer::TokenType::KEYW_FUNCTION: { + LogError(diagnostic::FUNC_EXPR); + ParseFunctionDeclaration(true, ir::ModifierFlags::NONE); + return AllocBrokenExpression(Lexer()->GetToken().Loc()); } case lexer::TokenType::PUNCTUATOR_FORMAT: { return ParseExpressionFormatPlaceholder(); diff --git a/ets2panda/test/ast/compiler/ets/invalid_two_functions.ets b/ets2panda/test/ast/compiler/ets/invalid_two_functions.ets index 62d52f75f5..f4850751e5 100644 --- a/ets2panda/test/ast/compiler/ets/invalid_two_functions.ets +++ b/ets2panda/test/ast/compiler/ets/invalid_two_functions.ets @@ -20,5 +20,6 @@ const b = a.map(function (e) { return e * 2; }); -/* @@? 16:2 Error SyntaxError: Unexpected token 'function'. */ -/* @@? 19:17 Error SyntaxError: Unexpected token 'function'. */ +/* @@? 16:2 Error SyntaxError: Function expressions are not supported, use arrow functions instead */ +/* @@? 19:17 Error SyntaxError: Function expressions are not supported, use arrow functions instead */ +/* @@? 19:28 Error SyntaxError: Parameter declaration should have an explicit type annotation. */ diff --git a/ets2panda/test/ast/compiler/ets/keywords/issue26215_restricted_this.ets b/ets2panda/test/ast/compiler/ets/keywords/issue26215_restricted_this.ets index cd9e3c4376..4e6aabb12a 100644 --- a/ets2panda/test/ast/compiler/ets/keywords/issue26215_restricted_this.ets +++ b/ets2panda/test/ast/compiler/ets/keywords/issue26215_restricted_this.ets @@ -17,4 +17,5 @@ declare namespace this { } +/* @@? 16:19 Error SyntaxError: Hard keyword 'this' cannot be used as identifier */ /* @@? 16:19 Error SyntaxError: Identifier expected, got 'this'. */ diff --git a/ets2panda/test/ast/parser/ets/decl_in_param.ets b/ets2panda/test/ast/parser/ets/decl_in_param.ets new file mode 100644 index 0000000000..39e7ac9b8f --- /dev/null +++ b/ets2panda/test/ast/parser/ets/decl_in_param.ets @@ -0,0 +1,24 @@ +/* + * 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 f(public x: number){ +} +class C{ + constructor(public m:number) {} + m(public x:number) {} +} +/* @@? 16:12 Error SyntaxError: Declaring fields in parameter list is not supported */ +/* @@? 19:17 Error SyntaxError: Declaring fields in parameter list is not supported */ +/* @@? 20:7 Error SyntaxError: Declaring fields in parameter list is not supported */ diff --git a/ets2panda/test/ast/parser/ets/empty_array_map_inference_fail.ets b/ets2panda/test/ast/parser/ets/empty_array_map_inference_fail.ets index 0d648f4ea7..e085a3efaf 100644 --- a/ets2panda/test/ast/parser/ets/empty_array_map_inference_fail.ets +++ b/ets2panda/test/ast/parser/ets/empty_array_map_inference_fail.ets @@ -21,6 +21,7 @@ return x+1; }); -/* @@? 16:2 Error SyntaxError: Unexpected token 'function'. */ +/* @@? 16:2 Error SyntaxError: Function expressions are not supported, use arrow functions instead */ /* @@? 20:1 Error TypeError: Can't resolve array type */ -/* @@? 20:8 Error SyntaxError: Unexpected token 'function'. */ +/* @@? 20:8 Error SyntaxError: Function expressions are not supported, use arrow functions instead */ +/* @@? 20:18 Error SyntaxError: Parameter declaration should have an explicit type annotation. */ diff --git a/ets2panda/util/diagnostic/syntax.yaml b/ets2panda/util/diagnostic/syntax.yaml index 1c6454cf5b..fef5d62ff2 100644 --- a/ets2panda/util/diagnostic/syntax.yaml +++ b/ets2panda/util/diagnostic/syntax.yaml @@ -1279,3 +1279,11 @@ syntax: - name: NOT_AS_OBJECT id: 318 message: "{} cannot be used as object." + +- name: FIELD_IN_PARAM + id: 319 + message: "Declaring fields in parameter list is not supported" + +- name: FUNC_EXPR + id: 320 + message: "Function expressions are not supported, use arrow functions instead" -- Gitee