From d33c6bdca3a8b67c3ec939e84809c1ffa8de8d0d Mon Sep 17 00:00:00 2001 From: Gabor Aron Takacs Date: Fri, 20 Jun 2025 14:46:45 +0200 Subject: [PATCH] Add diagnostic for obj literals to declare type Fixes #23580 internal issue. Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICGR8T Change-Id: Ia204449b965d9431c91951b359eda1574e5a38fa Signed-off-by: Gabor Aron Takacs --- ets2panda/parser/ETSparserTypes.cpp | 11 +++ .../compiler/ets/class_cyclic_constructor.ets | 10 ++- .../compiler/ets/keyof_invalid_argument.ets | 48 ++++++------- .../compiler/ets/parameter_anonymous_type.ets | 2 +- .../ets/FixedArray/functionTypeParam_neg2.ets | 7 +- .../ast/parser/ets/MultipleFunctionErrors.ets | 7 +- .../ast/parser/ets/circular_type_in_alias.ets | 26 ++++--- .../ast/parser/ets/functionTypeParam_neg2.ets | 7 +- .../ets/generic_type_alias_clone_fix.ets | 9 +-- .../invalid_recursive_generic_union_type.ets | 23 ++----- .../parser/ets/invalid_type_assignment.ets | 8 +-- .../ast/parser/ets/namespace_bad_token.ets | 2 +- .../ets/recursive_exported_structure.ets | 2 +- .../ets/type_node_clone_assertion_fix.ets | 8 +-- .../test/ast/parser/ets/type_references.ets | 12 +--- .../parser/ets/typenode_clone_brokentype.ets | 16 ++--- .../ets/typenode_clone_comprehensive.ets | 68 +++++++------------ .../parser/ets/typenode_clone_primitives.ets | 12 +--- .../ets/types_no_object_lit_to_decl.ets | 19 ++++++ .../ets/types_no_object_lit_to_decl_2.ets | 19 ++++++ .../unit/lsp/refactors_convert_chain_test.cpp | 20 +++--- ets2panda/util/diagnostic/syntax.yaml | 4 ++ 22 files changed, 160 insertions(+), 180 deletions(-) create mode 100644 ets2panda/test/ast/parser/ets/types_no_object_lit_to_decl.ets create mode 100644 ets2panda/test/ast/parser/ets/types_no_object_lit_to_decl_2.ets diff --git a/ets2panda/parser/ETSparserTypes.cpp b/ets2panda/parser/ETSparserTypes.cpp index 3b0f7ea5c6..5fa69bbfd2 100644 --- a/ets2panda/parser/ETSparserTypes.cpp +++ b/ets2panda/parser/ETSparserTypes.cpp @@ -371,6 +371,17 @@ std::pair ETSParser::GetTypeAnnotationFromToken(TypeAnnota return std::make_pair(ParseETSTupleType(options), true); case lexer::TokenType::KEYW_THIS: return std::make_pair(ParseThisType(options), true); + case lexer::TokenType::PUNCTUATOR_LEFT_BRACE: + if (((*options) & TypeAnnotationParsingOptions::REPORT_ERROR) != 0) { + auto startPos = Lexer()->GetToken().Start(); + auto modifiers = ir::ClassDefinitionModifiers::ID_REQUIRED | ir::ClassDefinitionModifiers::CLASS_DECL | + ir::ClassDefinitionModifiers::DECLARATION; + auto flags = ir::ModifierFlags::NONE; + ParseClassBody(modifiers, flags); + LogError(diagnostic::ERROR_ARKTS_NO_OBJ_LITERAL_TO_DECL_TYPE, {}, startPos); + return {AllocBrokenType({startPos, Lexer()->GetToken().End()}), false}; + } + [[fallthrough]]; default: { return {nullptr, true}; } diff --git a/ets2panda/test/ast/compiler/ets/class_cyclic_constructor.ets b/ets2panda/test/ast/compiler/ets/class_cyclic_constructor.ets index 68b81eef70..14dfc9d81c 100644 --- a/ets2panda/test/ast/compiler/ets/class_cyclic_constructor.ets +++ b/ets2panda/test/ast/compiler/ets/class_cyclic_constructor.ets @@ -34,16 +34,14 @@ class A { /* @@? 24:9 Error SyntaxError: Unexpected token, expected ',' or ')'. */ /* @@? 24:9 Error SyntaxError: Unexpected token 'let'. */ /* @@? 24:9 Error SyntaxError: Unexpected token, expected an identifier. */ -/* @@? 24:20 Error SyntaxError: Invalid Type. */ -/* @@? 24:20 Error SyntaxError: Unexpected token '{'. */ +/* @@? 24:20 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ /* @@? 24:21 Error SyntaxError: Unexpected token '{'. */ /* @@? 24:23 Error SyntaxError: Field type annotation expected. */ /* @@? 24:23 Error SyntaxError: Unexpected token '.'. */ /* @@? 24:31 Error SyntaxError: Field type annotation expected. */ -/* @@? 24:32 Error SyntaxError: Unexpected token '}'. */ -/* @@? 24:37 Error SyntaxError: Unexpected token. */ -/* @@? 24:38 Error SyntaxError: Unexpected token. */ -/* @@? 24:51 Error SyntaxError: Unexpected token '}'. */ +/* @@? 24:34 Error SyntaxError: Unexpected token '='. */ +/* @@? 24:36 Error SyntaxError: Unexpected token '{'. */ +/* @@? 24:38 Error TypeError: Unresolved reference caches */ /* @@? 25:21 Error TypeError: Expected 0 arguments, got 1. */ /* @@? 25:21 Error TypeError: No matching construct signature for class_cyclic_constructor.A(...tuple) */ /* @@? 25:27 Error TypeError: Spread argument cannot be passed for ordinary parameter. */ diff --git a/ets2panda/test/ast/compiler/ets/keyof_invalid_argument.ets b/ets2panda/test/ast/compiler/ets/keyof_invalid_argument.ets index 2f2807b6f5..77031130fb 100644 --- a/ets2panda/test/ast/compiler/ets/keyof_invalid_argument.ets +++ b/ets2panda/test/ast/compiler/ets/keyof_invalid_argument.ets @@ -23,46 +23,40 @@ class ObservableImpl extends Observable { type NestedKey = T[K] extends object ? keyof T[K] : never; -/* @@? 16:24 Error SyntaxError: Unexpected token, expected ',' or ')'. */ -/* @@? 16:24 Error SyntaxError: Invalid Type. */ -/* @@? 16:26 Error SyntaxError: Unexpected token ','. */ -/* @@? 16:28 Error SyntaxError: Unexpected token 'k'. */ -/* @@? 16:31 Error SyntaxError: Label must be followed by a loop statement. */ -/* @@? 16:31 Error TypeError: Unresolved reference keyof */ -/* @@? 16:42 Error SyntaxError: Invalid Type. */ -/* @@? 16:42 Error SyntaxError: Unexpected token, expected ')'. */ -/* @@? 16:45 Error SyntaxError: Unexpected token ')'. */ -/* @@? 16:47 Error SyntaxError: Unexpected token '{'. */ +/* @@? 16:24 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ +/* @@? 16:42 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ +/* @@? 16:45 Error TypeError: The `keyof` keyword can only be used for class or interface type. */ /* @@? 18:33 Error TypeError: Cannot find type 'Observable'. */ /* @@? 18:33 Error TypeError: The super type of 'ObservableImpl' class is not extensible. */ -/* @@? 20:9 Error TypeError: Type 'ObservableImpl' is generic but type argument were not provided. */ -/* @@? 20:24 Error SyntaxError: Invalid Type. */ -/* @@? 20:24 Error SyntaxError: Unexpected token, expected '>'. */ -/* @@? 20:27 Error TypeError: Unresolved reference K */ -/* @@? 20:29 Error SyntaxError: Unexpected token, expected ',' or ']'. */ -/* @@? 20:29 Error SyntaxError: Unexpected token 'in'. */ -/* @@? 20:29 Error TypeError: Unresolved reference in */ -/* @@? 20:32 Error SyntaxError: Unexpected token 'keyof'. */ -/* @@? 20:32 Error TypeError: This expression is not callable. */ -/* @@? 20:41 Error SyntaxError: Unexpected token, expected ')'. */ +/* @@? 20:24 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ +/* @@? 20:27 Error TypeError: Indexed signatures are not allowed. Use arrays instead! */ +/* @@? 20:31 Error SyntaxError: Field type annotation expected. */ +/* @@? 20:41 Error SyntaxError: Unexpected token '&'. */ +/* @@? 20:41 Error SyntaxError: Unexpected token, expected ',' or ')'. */ +/* @@? 20:41 Error SyntaxError: Parameter declaration should have an explicit type annotation. */ +/* @@? 20:44 Error SyntaxError: Unexpected token ')'. */ +/* @@? 20:44 Error SyntaxError: Field type annotation expected. */ /* @@? 20:45 Error SyntaxError: Unexpected token ']'. */ /* @@? 20:46 Error SyntaxError: Unexpected token ':'. */ -/* @@? 20:46 Error TypeError: Indexed access is not supported for such expression type. */ -/* @@? 20:60 Error SyntaxError: Unexpected token '>'. */ -/* @@? 20:61 Error SyntaxError: Unexpected token '('. */ -/* @@? 20:62 Error SyntaxError: Unexpected token ')'. */ -/* @@? 22:1 Error SyntaxError: Unexpected token '}'. */ +/* @@? 20:48 Error SyntaxError: Unexpected token '('. */ +/* @@? 20:50 Error SyntaxError: Field type annotation expected. */ +/* @@? 20:51 Error SyntaxError: Unexpected token '&'. */ +/* @@? 20:54 Error SyntaxError: Field type annotation expected. */ +/* @@? 20:54 Error SyntaxError: Unexpected token ')'. */ +/* @@? 20:56 Error TypeError: Indexed signatures are not allowed. Use arrays instead! */ +/* @@? 20:57 Error SyntaxError: Unexpected token ']'. */ /* @@? 24:36 Error TypeError: The `keyof` keyword can only be used for class or interface type. */ -/* @@? 24:42 Error SyntaxError: Unexpected token ']'. */ /* @@? 24:42 Error SyntaxError: Unexpected token, expected ']'. */ +/* @@? 24:42 Error SyntaxError: Unexpected token ']'. */ /* @@? 24:43 Error SyntaxError: Unexpected token ']'. */ /* @@? 24:45 Error SyntaxError: Unexpected token 'extends'. */ /* @@? 24:53 Error SyntaxError: Unexpected token 'object'. */ /* @@? 24:53 Error TypeError: Type name 'object' used in the wrong context */ +/* @@? 24:62 Error TypeError: Unresolved reference keyof */ /* @@? 24:68 Error SyntaxError: Unexpected token. */ /* @@? 24:68 Error TypeError: Unresolved reference T */ /* @@? 24:68 Error TypeError: Indexed access is not supported for such expression type. */ /* @@? 24:70 Error SyntaxError: Unexpected token, expected ']'. */ /* @@? 24:73 Error SyntaxError: Unexpected token ':'. */ -/* @@? 24:75 Error SyntaxError: Unexpected token 'never'. */ /* @@? 24:75 Error SyntaxError: Class cannot be used as object. */ +/* @@? 24:75 Error SyntaxError: Unexpected token 'never'. */ diff --git a/ets2panda/test/ast/compiler/ets/parameter_anonymous_type.ets b/ets2panda/test/ast/compiler/ets/parameter_anonymous_type.ets index a84669385c..39968154fe 100644 --- a/ets2panda/test/ast/compiler/ets/parameter_anonymous_type.ets +++ b/ets2panda/test/ast/compiler/ets/parameter_anonymous_type.ets @@ -20,4 +20,4 @@ const _innerFunc = (arg: { x: number } | undefined): number => { return arg.x; }; -/* @@? 16:26 Error SyntaxError: Invalid Type. */ +/* @@? 16:26 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ diff --git a/ets2panda/test/ast/parser/ets/FixedArray/functionTypeParam_neg2.ets b/ets2panda/test/ast/parser/ets/FixedArray/functionTypeParam_neg2.ets index 6651396d4b..49a08ff7e5 100644 --- a/ets2panda/test/ast/parser/ets/FixedArray/functionTypeParam_neg2.ets +++ b/ets2panda/test/ast/parser/ets/FixedArray/functionTypeParam_neg2.ets @@ -23,8 +23,8 @@ declare class Environment { static foo7(props1: {key:string, value:int}[], props2: FixedArray): void; } -/* @@? 17:23 Error SyntaxError: Invalid Type. */ -/* @@? 18:25 Error SyntaxError: Invalid Type. */ +/* @@? 17:23 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ +/* @@? 18:25 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ /* @@? 19:25 Error SyntaxError: Invalid Type. */ /* @@? 21:20 Error SyntaxError: Invalid Type. */ /* @@? 21:28 Error SyntaxError: Invalid Type. */ @@ -32,4 +32,5 @@ declare class Environment { /* @@? 21:37 Error SyntaxError: Unexpected token, expected '('. */ /* @@? 21:37 Error SyntaxError: Invalid Type. */ /* @@? 22:20 Error SyntaxError: Invalid Type. */ -/* @@? 23:25 Error SyntaxError: Invalid Type. */ \ No newline at end of file +/* @@? 23:25 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ +/* @@? 23:36 Error SyntaxError: Unexpected token ','. */ diff --git a/ets2panda/test/ast/parser/ets/MultipleFunctionErrors.ets b/ets2panda/test/ast/parser/ets/MultipleFunctionErrors.ets index 85f7f8a871..e4ac2d3578 100644 --- a/ets2panda/test/ast/parser/ets/MultipleFunctionErrors.ets +++ b/ets2panda/test/ast/parser/ets/MultipleFunctionErrors.ets @@ -17,9 +17,12 @@ function /* @@ label */(): void { } function /* @@ label1 */(): /* @@ label2 */{ - return 77; + /* @@ label3 */return /* @@ label4 */77; } /* @@@ label Error SyntaxError: Unexpected token, expected an identifier. */ /* @@@ label1 Error SyntaxError: Unexpected token, expected an identifier. */ -/* @@@ label2 Error SyntaxError: Invalid Type. */ +/* @@@ label1 Error TypeError: Only abstract or native methods can't have body. */ +/* @@@ label2 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ +/* @@@ label3 Error SyntaxError: Unexpected token 'return'. */ +/* @@@ label4 Error SyntaxError: Unexpected token '77'. */ diff --git a/ets2panda/test/ast/parser/ets/circular_type_in_alias.ets b/ets2panda/test/ast/parser/ets/circular_type_in_alias.ets index 920263f091..b951ba4ff5 100644 --- a/ets2panda/test/ast/parser/ets/circular_type_in_alias.ets +++ b/ets2panda/test/ast/parser/ets/circular_type_in_alias.ets @@ -18,21 +18,19 @@ type Loop> = { }; /* @@? 16:24 Error TypeError: Circular type alias reference */ -/* @@? 16:38 Error SyntaxError: Invalid Type. */ -/* @@? 17:6 Error TypeError: Unresolved reference P */ -/* @@? 17:8 Error SyntaxError: Unexpected token, expected ',' or ']'. */ -/* @@? 17:8 Error SyntaxError: Unexpected token 'in'. */ -/* @@? 17:8 Error TypeError: Unresolved reference in */ -/* @@? 17:11 Error SyntaxError: Unexpected token 'keyof'. */ -/* @@? 17:11 Error TypeError: Unresolved reference keyof */ -/* @@? 17:17 Error SyntaxError: Unexpected token 'T'. */ -/* @@? 17:17 Error TypeError: Unresolved reference T */ +/* @@? 16:38 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ +/* @@? 17:6 Error TypeError: Indexed signatures are not allowed. Use arrays instead! */ +/* @@? 17:10 Error SyntaxError: Field type annotation expected. */ +/* @@? 17:16 Error SyntaxError: Field type annotation expected. */ /* @@? 17:18 Error SyntaxError: Unexpected token ']'. */ +/* @@? 17:18 Error SyntaxError: Field type annotation expected. */ /* @@? 17:19 Error SyntaxError: Unexpected token ':'. */ -/* @@? 17:21 Error SyntaxError: Unexpected token 'U'. */ -/* @@? 17:21 Error TypeError: Unresolved reference U */ -/* @@? 17:21 Error TypeError: Indexed access is not supported for such expression type. */ +/* @@? 17:22 Error SyntaxError: Field type annotation expected. */ +/* @@? 17:23 Error TypeError: Indexed signatures are not allowed. Use arrays instead! */ +/* @@? 17:24 Error SyntaxError: Unexpected token ']'. */ /* @@? 17:26 Error SyntaxError: Unexpected token 'extends'. */ /* @@? 17:34 Error SyntaxError: Unexpected token 'boolean'. */ -/* @@? 17:44 Error TypeError: Type name 'number' used in the wrong context */ -/* @@? 17:53 Error TypeError: Type name 'string' used in the wrong context */ +/* @@? 17:42 Error SyntaxError: Unexpected token '?'. */ +/* @@? 17:44 Error SyntaxError: number is a predefined type, cannot be used as an identifier */ +/* @@? 17:51 Error SyntaxError: Unexpected token ':'. */ +/* @@? 17:59 Error SyntaxError: Field type annotation expected. */ \ No newline at end of file diff --git a/ets2panda/test/ast/parser/ets/functionTypeParam_neg2.ets b/ets2panda/test/ast/parser/ets/functionTypeParam_neg2.ets index b397027c6b..3f31cfcb8c 100644 --- a/ets2panda/test/ast/parser/ets/functionTypeParam_neg2.ets +++ b/ets2panda/test/ast/parser/ets/functionTypeParam_neg2.ets @@ -23,8 +23,8 @@ declare class Environment { static foo7(props1: {key:string, value:int}[], props2: int[]): void; } -/* @@? 17:23 Error SyntaxError: Invalid Type. */ -/* @@? 18:25 Error SyntaxError: Invalid Type. */ +/* @@? 17:23 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ +/* @@? 18:25 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ /* @@? 19:25 Error SyntaxError: Invalid Type. */ /* @@? 21:20 Error SyntaxError: Invalid Type. */ /* @@? 21:28 Error SyntaxError: Invalid Type. */ @@ -32,4 +32,5 @@ declare class Environment { /* @@? 21:37 Error SyntaxError: Unexpected token, expected '('. */ /* @@? 21:37 Error SyntaxError: Invalid Type. */ /* @@? 22:20 Error SyntaxError: Invalid Type. */ -/* @@? 23:25 Error SyntaxError: Invalid Type. */ \ No newline at end of file +/* @@? 23:25 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ +/* @@? 23:36 Error SyntaxError: Unexpected token ','. */ diff --git a/ets2panda/test/ast/parser/ets/generic_type_alias_clone_fix.ets b/ets2panda/test/ast/parser/ets/generic_type_alias_clone_fix.ets index 661d448ab5..b3b1333cee 100644 --- a/ets2panda/test/ast/parser/ets/generic_type_alias_clone_fix.ets +++ b/ets2panda/test/ast/parser/ets/generic_type_alias_clone_fix.ets @@ -21,11 +21,6 @@ type RecordMap = { n: number }; let myMap: MyMap<"n"> = { kind: "n" }; -/* Expected errors - these should NOT cause assertion failures or crashes: */ /* @@? 16:37 Error TypeError: The `keyof` keyword can only be used for class or interface type. */ -/* @@? 16:41 Error SyntaxError: Invalid Type. */ -/* @@? 17:11 Error SyntaxError: Label must be followed by a loop statement. */ -/* @@? 17:11 Error TypeError: Unresolved reference K */ -/* @@? 20:18 Error SyntaxError: Invalid Type. */ -/* @@? 20:23 Error SyntaxError: Label must be followed by a loop statement. */ -/* @@? 20:23 Error TypeError: Type name 'number' used in the wrong context */ \ No newline at end of file +/* @@? 16:41 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ +/* @@? 20:18 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ diff --git a/ets2panda/test/ast/parser/ets/invalid_recursive_generic_union_type.ets b/ets2panda/test/ast/parser/ets/invalid_recursive_generic_union_type.ets index 2bf921b5da..bbe7b44619 100644 --- a/ets2panda/test/ast/parser/ets/invalid_recursive_generic_union_type.ets +++ b/ets2panda/test/ast/parser/ets/invalid_recursive_generic_union_type.ets @@ -23,21 +23,8 @@ type Container = T | { [i: string]: Container }; declare namespace Test1 { } -/* @@? 21:25 Error SyntaxError: Invalid Type. */ -/* @@? 21:28 Error TypeError: Unresolved reference i */ -/* @@? 21:29 Error SyntaxError: Unexpected token, expected ',' or ']'. */ -/* @@? 21:29 Error SyntaxError: Unexpected token ':'. */ -/* @@? 21:31 Error SyntaxError: Unexpected token 'string'. */ -/* @@? 21:31 Error TypeError: Type name 'string' used in the wrong context */ -/* @@? 21:37 Error SyntaxError: Unexpected token ']'. */ -/* @@? 21:38 Error SyntaxError: Unexpected token ':'. */ -/* @@? 21:40 Error SyntaxError: Unexpected token 'Container'. */ -/* @@? 21:40 Error TypeError: This expression is not callable. */ -/* @@? 21:50 Error TypeError: Cannot find type 'T'. */ -/* @@? 21:53 Error SyntaxError: Unexpected token, expected '('. */ -/* @@? 21:54 Error SyntaxError: Unexpected token ';'. */ -/* @@? 23:1 Error SyntaxError: Unexpected token, expected ',' or ')'. */ -/* @@? 23:1 Error TypeError: Unresolved reference declare */ -/* @@? 23:9 Error SyntaxError: Namespace is allowed only at the top level or inside a namespace. */ -/* @@? 23:9 Error SyntaxError: Unexpected token 'namespace'. */ -/* @@? 44:1 Error SyntaxError: Expected '}', got 'end of stream'. */ +/* @@? 21:25 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ +/* @@? 21:28 Error TypeError: Indexed signatures are not allowed. Use arrays instead! */ +/* @@? 21:49 Error SyntaxError: Unexpected token '<'. */ +/* @@? 21:51 Error SyntaxError: Field type annotation expected. */ +/* @@? 21:51 Error SyntaxError: Unexpected token '>'. */ diff --git a/ets2panda/test/ast/parser/ets/invalid_type_assignment.ets b/ets2panda/test/ast/parser/ets/invalid_type_assignment.ets index da4139c843..763dbf30f6 100644 --- a/ets2panda/test/ast/parser/ets/invalid_type_assignment.ets +++ b/ets2panda/test/ast/parser/ets/invalid_type_assignment.ets @@ -20,11 +20,7 @@ flags: [dynamic-ast] type Point = { x: number; y: number }; type AxeX = Point['x']; -/* @@? 20:18 Error SyntaxError: Invalid Type. */ -/* @@? 20:23 Error SyntaxError: Label must be followed by a loop statement. */ -/* @@? 20:23 Error TypeError: Type name 'number' used in the wrong context */ -/* @@? 20:34 Error SyntaxError: Label must be followed by a loop statement. */ -/* @@? 20:34 Error TypeError: Type name 'number' used in the wrong context */ +/* @@? 20:18 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ /* @@? 21:23 Error SyntaxError: Unexpected token, expected ']'. */ /* @@? 21:23 Error SyntaxError: Unexpected token ']'. */ -/* @@? 21:26 Error SyntaxError: Unexpected token ']'. */ +/* @@? 21:26 Error SyntaxError: Unexpected token ']'. */ \ No newline at end of file diff --git a/ets2panda/test/ast/parser/ets/namespace_bad_token.ets b/ets2panda/test/ast/parser/ets/namespace_bad_token.ets index 2b279dceae..5576913d33 100644 --- a/ets2panda/test/ast/parser/ets/namespace_bad_token.ets +++ b/ets2panda/test/ast/parser/ets/namespace_bad_token.ets @@ -17,5 +17,5 @@ declare namespace uiObserver { function on(options: { a: number }, callback: ): void; } -/* @@? 17:26 Error SyntaxError: Invalid Type. */ +/* @@? 17:26 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ /* @@? 17:51 Error SyntaxError: Invalid Type. */ \ No newline at end of file diff --git a/ets2panda/test/ast/parser/ets/recursive_exported_structure.ets b/ets2panda/test/ast/parser/ets/recursive_exported_structure.ets index 90fd2ccf79..25e4a6d0ea 100644 --- a/ets2panda/test/ast/parser/ets/recursive_exported_structure.ets +++ b/ets2panda/test/ast/parser/ets/recursive_exported_structure.ets @@ -88,7 +88,7 @@ const _exported: ExportedType = _exportedStructure; export default _exported; -/* @@? 26:26 Error SyntaxError: Invalid Type. */ +/* @@? 26:26 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ /* @@? 41:12 Error TypeError: No matching call signature for (...) */ /* @@? 41:23 Error TypeError: need to specify target type for class composite */ /* @@? 54:20 Error TypeError: No matching call signature for (...) */ diff --git a/ets2panda/test/ast/parser/ets/type_node_clone_assertion_fix.ets b/ets2panda/test/ast/parser/ets/type_node_clone_assertion_fix.ets index d28120b38d..911938c626 100644 --- a/ets2panda/test/ast/parser/ets/type_node_clone_assertion_fix.ets +++ b/ets2panda/test/ast/parser/ets/type_node_clone_assertion_fix.ets @@ -27,9 +27,5 @@ type RecordMap = { n: number }; // Expected compilation errors for unsupported TypeScript features in ETS: /* @@? 22:37 Error TypeError: The `keyof` keyword can only be used for class or interface type. */ -/* @@? 22:41 Error SyntaxError: Invalid Type. */ -/* @@? 23:11 Error SyntaxError: Label must be followed by a loop statement. */ -/* @@? 23:11 Error TypeError: Unresolved reference K */ -/* @@? 26:18 Error SyntaxError: Invalid Type. */ -/* @@? 26:23 Error SyntaxError: Label must be followed by a loop statement. */ -/* @@? 26:23 Error TypeError: Type name 'number' used in the wrong context */ \ No newline at end of file +/* @@? 22:41 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ +/* @@? 26:18 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ \ No newline at end of file diff --git a/ets2panda/test/ast/parser/ets/type_references.ets b/ets2panda/test/ast/parser/ets/type_references.ets index a5db99d97c..4659ad2318 100644 --- a/ets2panda/test/ast/parser/ets/type_references.ets +++ b/ets2panda/test/ast/parser/ets/type_references.ets @@ -20,14 +20,4 @@ let y: G<{a:String}, B> // Error /* @@? 18:8 Error TypeError: Cannot find type 'G'. */ /* @@? 19:8 Error TypeError: Cannot find type 'G'. */ -/* @@? 19:10 Error SyntaxError: Invalid Type. */ -/* @@? 19:10 Error SyntaxError: Unexpected token, expected '>'. */ -/* @@? 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 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'. */ -/* @@? 19:22 Error TypeError: Type name 'B' used in the wrong context */ -/* @@? 34:1 Error SyntaxError: Unexpected token 'end of stream'. */ +/* @@? 19:10 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ diff --git a/ets2panda/test/ast/parser/ets/typenode_clone_brokentype.ets b/ets2panda/test/ast/parser/ets/typenode_clone_brokentype.ets index f955112a64..3e8e77e5b8 100644 --- a/ets2panda/test/ast/parser/ets/typenode_clone_brokentype.ets +++ b/ets2panda/test/ast/parser/ets/typenode_clone_brokentype.ets @@ -39,21 +39,17 @@ type BrokenFunc = (param: T) => void; declare const broken1: BrokenType; declare const broken2: AnotherBroken; -/* Expected errors - these should NOT cause assertion failures or crashes: */ /* @@? 21:33 Error TypeError: Cannot find type 'UndefinedMap'. */ /* @@? 21:45 Error TypeError: The `keyof` keyword can only be used for class or interface type. */ -/* @@? 21:49 Error SyntaxError: Invalid Type. */ -/* @@? 22:11 Error SyntaxError: Label must be followed by a loop statement. */ -/* @@? 22:11 Error TypeError: Unresolved reference K */ +/* @@? 21:49 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ /* @@? 26:36 Error TypeError: Cannot find type 'NonExistent'. */ /* @@? 26:47 Error TypeError: The `keyof` keyword can only be used for class or interface type. */ /* @@? 27:27 Error TypeError: Cannot find type 'InvalidInterface'. */ -/* @@? 30:52 Error SyntaxError: Invalid Type. */ -/* @@? 31:13 Error SyntaxError: Label must be followed by a loop statement. */ +/* @@? 30:52 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ /* @@? 31:14 Error SyntaxError: Unexpected token ','. */ -/* @@? 32:12 Error SyntaxError: Class cannot be used as object. */ -/* @@? 32:12 Error SyntaxError: Label must be followed by a loop statement. */ -/* @@? 32:12 Error TypeError: Object type doesn't have proper index access method. */ +/* @@? 32:26 Error SyntaxError: Unexpected token, expected ']'. */ +/* @@? 32:26 Error SyntaxError: Unexpected token ']'. */ +/* @@? 32:27 Error SyntaxError: Unexpected token ']'. */ /* @@? 36:27 Error TypeError: Cannot find type 'UndefinedInterface'. */ /* @@? 39:35 Error TypeError: Cannot find type 'any'. */ -/* @@? 40:38 Error TypeError: Cannot find type 'any'. */ \ No newline at end of file +/* @@? 40:38 Error TypeError: Cannot find type 'any'. */ diff --git a/ets2panda/test/ast/parser/ets/typenode_clone_comprehensive.ets b/ets2panda/test/ast/parser/ets/typenode_clone_comprehensive.ets index e3f3d7459d..a741c2a82c 100644 --- a/ets2panda/test/ast/parser/ets/typenode_clone_comprehensive.ets +++ b/ets2panda/test/ast/parser/ets/typenode_clone_comprehensive.ets @@ -67,28 +67,19 @@ declare const test1: ComplexType<'n'>; declare const test2: ComplexType<'s'>; declare const test3: ComplexType<'b'>; -/* Expected errors (these are normal for ETS, but should not crash): */ -/* @@? 1:3 Error TypeError: Class 'UnionType' is already defined with different type. */ /* @@? 1:3 Error TypeError: Class 'TupleType' is already defined with different type. */ -/* @@? 21:19 Error SyntaxError: Invalid Type. */ -/* @@? 21:24 Error SyntaxError: Label must be followed by a loop statement. */ -/* @@? 21:24 Error TypeError: Type name 'number' used in the wrong context */ +/* @@? 1:3 Error TypeError: Class 'UnionType' is already defined with different type. */ +/* @@? 21:19 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ /* @@? 21:30 Error SyntaxError: Unexpected token ','. */ -/* @@? 21:32 Error SyntaxError: Unexpected token 's'. */ -/* @@? 21:35 Error SyntaxError: Label must be followed by a loop statement. */ -/* @@? 21:35 Error TypeError: Type name 'string' used in the wrong context */ /* @@? 21:41 Error SyntaxError: Unexpected token ','. */ -/* @@? 21:43 Error SyntaxError: Unexpected token 'b'. */ -/* @@? 21:46 Error SyntaxError: Unexpected token 'boolean'. */ -/* @@? 21:46 Error SyntaxError: Label must be followed by a loop statement. */ /* @@? 32:42 Error TypeError: The `keyof` keyword can only be used for class or interface type. */ /* @@? 35:44 Error TypeError: The `keyof` keyword can only be used for class or interface type. */ -/* @@? 35:59 Error SyntaxError: Unexpected token ']'. */ /* @@? 35:59 Error SyntaxError: Unexpected token, expected ']'. */ +/* @@? 35:59 Error SyntaxError: Unexpected token ']'. */ /* @@? 35:60 Error SyntaxError: Unexpected token ']'. */ /* @@? 38:19 Error TypeError: Cannot find type 'a'. */ -/* @@? 38:20 Error SyntaxError: Unexpected token, expected ',' or ']'. */ /* @@? 38:20 Error SyntaxError: Unexpected token ':'. */ +/* @@? 38:20 Error SyntaxError: Unexpected token, expected ',' or ']'. */ /* @@? 38:22 Error SyntaxError: Unexpected token 'number'. */ /* @@? 38:22 Error TypeError: Type name 'number' used in the wrong context */ /* @@? 38:28 Error SyntaxError: Unexpected token ','. */ @@ -96,45 +87,38 @@ declare const test3: ComplexType<'b'>; /* @@? 38:33 Error SyntaxError: Label must be followed by a loop statement. */ /* @@? 38:33 Error TypeError: Type name 'string' used in the wrong context */ /* @@? 38:39 Error SyntaxError: Unexpected token ']'. */ -/* @@? 41:19 Error SyntaxError: Invalid Type. */ -/* @@? 41:22 Error TypeError: Unresolved reference K */ -/* @@? 41:24 Error SyntaxError: Unexpected token, expected ',' or ']'. */ -/* @@? 41:24 Error SyntaxError: Unexpected token 'in'. */ -/* @@? 41:24 Error TypeError: Unresolved reference in */ -/* @@? 41:27 Error SyntaxError: Unexpected token 'keyof'. */ -/* @@? 41:27 Error TypeError: Unresolved reference keyof */ -/* @@? 41:33 Error SyntaxError: Unexpected token 'ObjectType'. */ -/* @@? 41:33 Error TypeError: Type name 'ObjectType' used in the wrong context */ +/* @@? 41:19 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ +/* @@? 41:22 Error TypeError: Indexed signatures are not allowed. Use arrays instead! */ +/* @@? 41:26 Error SyntaxError: Field type annotation expected. */ +/* @@? 41:32 Error SyntaxError: Field type annotation expected. */ /* @@? 41:43 Error SyntaxError: Unexpected token ']'. */ +/* @@? 41:43 Error SyntaxError: Field type annotation expected. */ /* @@? 41:44 Error SyntaxError: Unexpected token ':'. */ -/* @@? 41:46 Error SyntaxError: Unexpected token 'string'. */ -/* @@? 41:46 Error TypeError: Type name 'string' used in the wrong context */ +/* @@? 41:52 Error SyntaxError: Field type annotation expected. */ /* @@? 44:41 Error TypeError: The `keyof` keyword can only be used for class or interface type. */ /* @@? 44:60 Error SyntaxError: Unexpected token, expected ']'. */ /* @@? 54:34 Error TypeError: Cannot find type 'InvalidMap'. */ /* @@? 54:44 Error TypeError: The `keyof` keyword can only be used for class or interface type. */ -/* @@? 57:67 Error SyntaxError: Invalid Type. */ -/* @@? 58:11 Error SyntaxError: Label must be followed by a loop statement. */ +/* @@? 57:45 Error TypeError: The `keyof` keyword can only be used for class or interface type. */ +/* @@? 57:63 Error TypeError: The `keyof` keyword can only be used for class or interface type. */ +/* @@? 57:67 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ /* @@? 58:12 Error SyntaxError: Unexpected token ','. */ -/* @@? 59:12 Error SyntaxError: Label must be followed by a loop statement. */ -/* @@? 59:12 Error TypeError: Indexed access is not supported for such expression type. */ -/* @@? 59:12 Error TypeError: Type name 'ObjectType' used in the wrong context */ +/* @@? 59:23 Error SyntaxError: Unexpected token, expected ']'. */ +/* @@? 59:23 Error SyntaxError: Unexpected token ']'. */ +/* @@? 59:24 Error SyntaxError: Unexpected token ']'. */ /* @@? 59:25 Error SyntaxError: Unexpected token ','. */ -/* @@? 60:14 Error SyntaxError: Label must be followed by a loop statement. */ /* @@? 60:29 Error SyntaxError: Unexpected token, expected ']'. */ -/* @@? 60:36 Error SyntaxError: Unexpected token 'void'. */ /* @@? 60:40 Error SyntaxError: Unexpected token ','. */ -/* @@? 61:12 Error SyntaxError: Label must be followed by a loop statement. */ -/* @@? 61:16 Error TypeError: Type name 'ObjectType' used in the wrong context */ -/* @@? 61:16 Error TypeError: Indexed access is not supported for such expression type. */ +/* @@? 61:27 Error SyntaxError: Unexpected token, expected ']'. */ +/* @@? 61:28 Error SyntaxError: Unexpected token ']'. */ +/* @@? 61:29 Error SyntaxError: Unexpected token ']'. */ /* @@? 61:30 Error SyntaxError: Unexpected token ','. */ -/* @@? 62:13 Error SyntaxError: Label must be followed by a loop statement. */ -/* @@? 62:16 Error TypeError: Unresolved reference P */ -/* @@? 62:18 Error SyntaxError: Unexpected token, expected ',' or ']'. */ -/* @@? 62:18 Error SyntaxError: Unexpected token 'in'. */ -/* @@? 62:21 Error SyntaxError: Unexpected token 'K'. */ +/* @@? 62:13 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ +/* @@? 62:16 Error TypeError: Indexed signatures are not allowed. Use arrays instead! */ +/* @@? 62:20 Error SyntaxError: Field type annotation expected. */ /* @@? 62:22 Error SyntaxError: Unexpected token ']'. */ +/* @@? 62:22 Error SyntaxError: Field type annotation expected. */ /* @@? 62:23 Error SyntaxError: Unexpected token ':'. */ -/* @@? 62:25 Error SyntaxError: Unexpected token 'ObjectType'. */ -/* @@? 62:25 Error TypeError: Type name 'ObjectType' used in the wrong context */ -/* @@? 62:25 Error TypeError: Indexed access is not supported for such expression type. */ \ No newline at end of file +/* @@? 62:35 Error SyntaxError: Field type annotation expected. */ +/* @@? 62:36 Error TypeError: Indexed signatures are not allowed. Use arrays instead! */ +/* @@? 62:37 Error SyntaxError: Unexpected token ']'. */ diff --git a/ets2panda/test/ast/parser/ets/typenode_clone_primitives.ets b/ets2panda/test/ast/parser/ets/typenode_clone_primitives.ets index 19d5e3fed1..2cce27da50 100644 --- a/ets2panda/test/ast/parser/ets/typenode_clone_primitives.ets +++ b/ets2panda/test/ast/parser/ets/typenode_clone_primitives.ets @@ -46,18 +46,10 @@ declare const num: NumAlias<42>; declare const str: StrAlias<"test">; declare const bool: BoolAlias; -/* @@? 37:73 Error SyntaxError: Invalid Type. */ -/* @@? 38:15 Error SyntaxError: Label must be followed by a loop statement. */ -/* @@? 38:15 Error TypeError: Unresolved reference N */ +/* @@? 37:73 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ /* @@? 38:16 Error SyntaxError: Unexpected token ','. */ -/* @@? 39:15 Error SyntaxError: Label must be followed by a loop statement. */ -/* @@? 39:15 Error TypeError: Unresolved reference S */ /* @@? 39:16 Error SyntaxError: Unexpected token ','. */ -/* @@? 40:16 Error SyntaxError: Label must be followed by a loop statement. */ -/* @@? 40:16 Error TypeError: Unresolved reference B */ /* @@? 40:17 Error SyntaxError: Unexpected token ','. */ -/* @@? 41:17 Error SyntaxError: Label must be followed by a loop statement. */ -/* @@? 41:23 Error SyntaxError: Unexpected token 'void'. */ /* @@? 45:29 Error SyntaxError: Invalid Type. */ /* @@? 45:29 Error SyntaxError: Unexpected token, expected '>'. */ /* @@? 45:29 Error SyntaxError: Unexpected token '>'. */ @@ -65,4 +57,4 @@ declare const bool: BoolAlias; /* @@? 47:31 Error SyntaxError: Invalid Type. */ /* @@? 47:31 Error SyntaxError: Unexpected token, expected '>'. */ /* @@? 47:31 Error SyntaxError: Unexpected token '>'. */ -/* @@? 47:36 Error SyntaxError: Unexpected token ';'. */ \ No newline at end of file +/* @@? 47:36 Error SyntaxError: Unexpected token ';'. */ diff --git a/ets2panda/test/ast/parser/ets/types_no_object_lit_to_decl.ets b/ets2panda/test/ast/parser/ets/types_no_object_lit_to_decl.ets new file mode 100644 index 0000000000..633a00e7ac --- /dev/null +++ b/ets2panda/test/ast/parser/ets/types_no_object_lit_to_decl.ets @@ -0,0 +1,19 @@ +/* + * 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. + */ + +let o: /* @@ label */{ x: number/* @@ label2 */, y: number } = { x: 2, y: 3 } + +/* @@@ label Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ +/* @@@ label2 Error SyntaxError: Unexpected token ','. */ diff --git a/ets2panda/test/ast/parser/ets/types_no_object_lit_to_decl_2.ets b/ets2panda/test/ast/parser/ets/types_no_object_lit_to_decl_2.ets new file mode 100644 index 0000000000..dbbd45161e --- /dev/null +++ b/ets2panda/test/ast/parser/ets/types_no_object_lit_to_decl_2.ets @@ -0,0 +1,19 @@ +/* + * 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. + */ + +type S = Set + +/* @@@ label Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ +/* @@@ label2 Error SyntaxError: Unexpected token ','. */ diff --git a/ets2panda/test/unit/lsp/refactors_convert_chain_test.cpp b/ets2panda/test/unit/lsp/refactors_convert_chain_test.cpp index 514202b21a..3a53f51d66 100644 --- a/ets2panda/test/unit/lsp/refactors_convert_chain_test.cpp +++ b/ets2panda/test/unit/lsp/refactors_convert_chain_test.cpp @@ -57,14 +57,12 @@ TEST_F(LspChainRefTests, ConvertChainRefactor1) TEST_F(LspChainRefTests, ConvertChainRefactor2) { std::vector files = {"ConvertChainRefactor2.ets"}; - std::vector texts = {R"(interface Foo{ -bar?:{ -baz?:string | null; -} + std::vector texts = {R"(interface A { baz?:string | null; } +interface Foo{ +bar?: A } declare let foo: Foo; -let ccc = /*1*/foo.bar ? -foo.bar.baz : "whenFalse";/*2*/ +let ccc = /*1*/foo.bar ? foo.bar.baz : "whenFalse";/*2*/ )"}; auto filePaths = CreateTempFile(files, texts); @@ -87,14 +85,12 @@ foo.bar.baz : "whenFalse";/*2*/ TEST_F(LspChainRefTests, ConvertChainRefactor3) { std::vector files = {"ConvertChainRefactor3.ets"}; - std::vector texts = {R"(interface Foo{ -bar?:{ -baz: string; -} + std::vector texts = {R"(interface A { baz: string } +interface Foo{ +bar?: A } declare let foo: Foo; -let ccc = /*1*/foo.bar? -foo.bar.baz: "whenFalse";/*2*/ +let ccc = /*1*/foo.bar ? foo.bar.baz: "whenFalse";/*2*/ )"}; auto filePaths = CreateTempFile(files, texts); diff --git a/ets2panda/util/diagnostic/syntax.yaml b/ets2panda/util/diagnostic/syntax.yaml index a2ff88fa46..93369a3b33 100644 --- a/ets2panda/util/diagnostic/syntax.yaml +++ b/ets2panda/util/diagnostic/syntax.yaml @@ -230,6 +230,10 @@ syntax: id: 81515 message: "Constructor signatures are not supported in interfaces, use methods instead!" +- name: ERROR_ARKTS_NO_OBJ_LITERAL_TO_DECL_TYPE + id: 177354 + message: "Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly!" + - name: ERROR_ARKTS_NO_PRIVATE_IDENTIFIERS id: 298 message: "Use 'private' keyword to declare an identifier as private." -- Gitee