diff --git a/ets2panda/parser/ETSparserTypes.cpp b/ets2panda/parser/ETSparserTypes.cpp index 946e7611eda6860a9524045f088f7a7dd09d57ef..d83986bf0d2f2e25695d18a8bf833e5a22932b93 100644 --- a/ets2panda/parser/ETSparserTypes.cpp +++ b/ets2panda/parser/ETSparserTypes.cpp @@ -356,6 +356,10 @@ 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: { + LogError(diagnostic::ERROR_ARKTS_NO_OBJ_LITERAL_TO_DECL_TYPE); + return {nullptr, false}; + } default: { return {nullptr, true}; } diff --git a/ets2panda/test/ast/parser/ets/FixedArray/functionTypeParam_neg2.ets b/ets2panda/test/ast/parser/ets/FixedArray/functionTypeParam_neg2.ets index 6651396d4b4f70b98d33b6f13bddcc063ecc15c2..bc20df401347bada759c25e1277c84fd719057c9 100644 --- a/ets2panda/test/ast/parser/ets/FixedArray/functionTypeParam_neg2.ets +++ b/ets2panda/test/ast/parser/ets/FixedArray/functionTypeParam_neg2.ets @@ -23,7 +23,9 @@ declare class Environment { static foo7(props1: {key:string, value:int}[], props2: FixedArray): void; } +/* @@? 17:23 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ /* @@? 17:23 Error SyntaxError: Invalid Type. */ +/* @@? 18:25 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ /* @@? 18:25 Error SyntaxError: Invalid Type. */ /* @@? 19:25 Error SyntaxError: Invalid Type. */ /* @@? 21:20 Error SyntaxError: Invalid Type. */ @@ -32,4 +34,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: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ /* @@? 23:25 Error SyntaxError: Invalid Type. */ \ No newline at end of file diff --git a/ets2panda/test/ast/parser/ets/MultipleFunctionErrors.ets b/ets2panda/test/ast/parser/ets/MultipleFunctionErrors.ets index 85f7f8a87135c0e294950d3ebbe3a70f80ae0539..8947393c6f96f580748738de6339df8a9d437043 100644 --- a/ets2panda/test/ast/parser/ets/MultipleFunctionErrors.ets +++ b/ets2panda/test/ast/parser/ets/MultipleFunctionErrors.ets @@ -22,4 +22,5 @@ function /* @@ label1 */(): /* @@ label2 */{ /* @@@ label Error SyntaxError: Unexpected token, expected an identifier. */ /* @@@ label1 Error SyntaxError: Unexpected token, expected an identifier. */ +/* @@@ label2 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ /* @@@ label2 Error SyntaxError: Invalid Type. */ diff --git a/ets2panda/test/ast/parser/ets/functionTypeParam_neg2.ets b/ets2panda/test/ast/parser/ets/functionTypeParam_neg2.ets index b397027c6bc09776e6276193f9c9a1419bf51a80..1f28db725c9cb8e5c2d0783267cb8d545197716d 100644 --- a/ets2panda/test/ast/parser/ets/functionTypeParam_neg2.ets +++ b/ets2panda/test/ast/parser/ets/functionTypeParam_neg2.ets @@ -23,7 +23,9 @@ declare class Environment { static foo7(props1: {key:string, value:int}[], props2: int[]): void; } +/* @@? 17:23 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ /* @@? 17:23 Error SyntaxError: Invalid Type. */ +/* @@? 18:25 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ /* @@? 18:25 Error SyntaxError: Invalid Type. */ /* @@? 19:25 Error SyntaxError: Invalid Type. */ /* @@? 21:20 Error SyntaxError: Invalid Type. */ @@ -32,4 +34,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: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ /* @@? 23:25 Error SyntaxError: Invalid Type. */ \ No newline at end of file diff --git a/ets2panda/test/ast/parser/ets/invalid_type_assignment.ets b/ets2panda/test/ast/parser/ets/invalid_type_assignment.ets index da4139c843567afddecb1a1a2fdbe69e620823ab..ac1556ab56db7c799a169466d83092837fa17388 100644 --- a/ets2panda/test/ast/parser/ets/invalid_type_assignment.ets +++ b/ets2panda/test/ast/parser/ets/invalid_type_assignment.ets @@ -20,6 +20,7 @@ flags: [dynamic-ast] type Point = { x: number; y: number }; type AxeX = Point['x']; +/* @@? 20:18 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ /* @@? 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 */ diff --git a/ets2panda/test/ast/parser/ets/namespace_bad_token.ets b/ets2panda/test/ast/parser/ets/namespace_bad_token.ets index 2b279dceae922adf414b83d7989d4b169ba60f3e..c6dc045e0dcdb377e46a420b09b4cf72762ebe4d 100644 --- a/ets2panda/test/ast/parser/ets/namespace_bad_token.ets +++ b/ets2panda/test/ast/parser/ets/namespace_bad_token.ets @@ -17,5 +17,6 @@ declare namespace uiObserver { function on(options: { a: number }, callback: ): void; } +/* @@? 17:26 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ /* @@? 17:26 Error SyntaxError: Invalid Type. */ /* @@? 17:51 Error SyntaxError: Invalid Type. */ \ 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 b689bb2c97d77d04ebab704d607253525626d531..95c6ccaf77fada179a08fedf83f4746c1257d1b3 100644 --- a/ets2panda/test/ast/parser/ets/type_references.ets +++ b/ets2panda/test/ast/parser/ets/type_references.ets @@ -20,6 +20,7 @@ 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: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ /* @@? 19:10 Error SyntaxError: Invalid Type. */ /* @@? 19:10 Error SyntaxError: Unexpected token, expected '>'. */ /* @@? 19:10 Error SyntaxError: Unexpected token '>'. */ @@ -30,4 +31,4 @@ let y: G<{a:String}, B> // Error /* @@? 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'. */ +/* @@? 35:1 Error SyntaxError: Unexpected token 'end of stream'. */ 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 0000000000000000000000000000000000000000..a044653ebd4701d83a148acad3f94844e98fcbd3 --- /dev/null +++ b/ets2panda/test/ast/parser/ets/types_no_object_lit_to_decl.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. + */ + +let o: /* @@ label1 */{ x: /* @@ label2 */number/* @@ label3 */, /* @@ label4 */y: /* @@ label5 */number } /* @@ label6 */= /* @@ label7 */{ x: /* @@ label8 */2/* @@ label9 */, /* @@ label10 */y: /* @@ label11 */3 } + +/* @@@ label1 Error SyntaxError: Invalid Type. */ +/* @@@ label1 Error SyntaxError: Unexpected token '{'. */ +/* @@@ label1 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ +/* @@@ label2 Error SyntaxError: Label must be followed by a loop statement. */ +/* @@@ label2 Error TypeError: Type name 'number' used in the wrong context */ +/* @@@ label3 Error SyntaxError: Unexpected token ','. */ +/* @@@ label4 Error SyntaxError: Unexpected token 'y'. */ +/* @@@ label5 Error SyntaxError: Label must be followed by a loop statement. */ +/* @@@ label5 Error TypeError: Type name 'number' used in the wrong context */ +/* @@@ label6 Error SyntaxError: Unexpected token '='. */ +/* @@@ label7 Error SyntaxError: Unexpected token '{'. */ +/* @@@ label8 Error SyntaxError: Label must be followed by a loop statement. */ +/* @@@ label9 Error SyntaxError: Unexpected token ','. */ +/* @@@ label10 Error SyntaxError: Unexpected token 'y'. */ +/* @@@ label11 Error SyntaxError: Label must be followed by a loop statement. */ 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 0000000000000000000000000000000000000000..1d2e1ad805c94b35ca51b382c860965398d25cb4 --- /dev/null +++ b/ets2panda/test/ast/parser/ets/types_no_object_lit_to_decl_2.ets @@ -0,0 +1,31 @@ +/* + * 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 = /* @@ label1 */Set + +/* @@@ label1 Error TypeError: Type 'Set' is generic but type argument were not provided. */ +/* @@@ label2 Error SyntaxError: Unexpected token '>'. */ +/* @@@ label2 Error SyntaxError: Invalid Type. */ +/* @@@ label2 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ +/* @@@ label2 Error SyntaxError: Unexpected token, expected '>'. */ +/* @@@ label3 Error SyntaxError: Unexpected token 'x'. */ +/* @@@ label4 Error SyntaxError: Label must be followed by a loop statement. */ +/* @@@ label4 Error TypeError: Type name 'number' used in the wrong context */ +/* @@@ label5 Error SyntaxError: Unexpected token ','. */ +/* @@@ label6 Error SyntaxError: Unexpected token 'y'. */ +/* @@@ label7 Error SyntaxError: Label must be followed by a loop statement. */ +/* @@@ label7 Error TypeError: Type name 'number' used in the wrong context */ +/* @@@ label8 Error SyntaxError: Unexpected token '}'. */ +/* @@? 32:1 Error SyntaxError: Unexpected token 'end of stream'. */ diff --git a/ets2panda/util/diagnostic/syntax.yaml b/ets2panda/util/diagnostic/syntax.yaml index 8a1a9bafa9cc0a3418103f5191e12558fdcde633..05c24393291bb0cad13624a6f820edcbe9844f54 100644 --- a/ets2panda/util/diagnostic/syntax.yaml +++ b/ets2panda/util/diagnostic/syntax.yaml @@ -1267,3 +1267,7 @@ syntax: - name: GENERATOR_FUNCTION id: 314 message: "Generator functions are not supported, please use async/await mechanism for multitasking" + +- name: ERROR_ARKTS_NO_OBJ_LITERAL_TO_DECL_TYPE + id: 315 + message: "Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly!"