diff --git a/ets2panda/parser/ETSparserExpressions.cpp b/ets2panda/parser/ETSparserExpressions.cpp index 2e07b4f37e49a7230e748ad61971ab7cd19b4bc8..fa32091ce90428fc6b46140ae3fc7855097d0bc4 100644 --- a/ets2panda/parser/ETSparserExpressions.cpp +++ b/ets2panda/parser/ETSparserExpressions.cpp @@ -314,7 +314,8 @@ ir::Expression *ETSParser::ParseDefaultPrimaryExpression(ExpressionParseFlags fl Lexer()->NextToken(); // eat '.' } - if (Lexer()->GetToken().Type() == lexer::TokenType::KEYW_CLASS || IsStructKeyword()) { + if ((Lexer()->GetToken().Type() == lexer::TokenType::KEYW_CLASS || IsStructKeyword()) && + potentialType->IsBrokenTypeNode()) { Lexer()->NextToken(); // eat 'class' and 'struct' auto *classLiteral = AllocNode(potentialType); ES2PANDA_ASSERT(classLiteral != nullptr); diff --git a/ets2panda/test/ast/compiler/ets/parser_format.ets b/ets2panda/test/ast/compiler/ets/parser_format.ets index a468621ea1b27722401f57c863f3fa0d443129f1..37c031a0b852e272c5f004f2a4abf516f327b608 100644 --- a/ets2panda/test/ast/compiler/ets/parser_format.ets +++ b/ets2panda/test/ast/compiler/ets/parser_format.ets @@ -17,10 +17,9 @@ declaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaare struct MainProg2 { @@Stave } -/* @@? 16:1 Error TypeError: Cannot find type 'declaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaare'. */ -/* @@? 16:1 Error TypeError: Class literal is not yet supported. */ -/* @@? 16:46 Error SyntaxError: Unexpected token 'MainProg2'. */ -/* @@? 16:46 Error TypeError: Unresolved reference MainProg2 */ -/* @@? 16:56 Error SyntaxError: Unexpected token '{'. */ +/* @@? 16:1 Error TypeError: Unresolved reference declaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaare */ +/* @@? 16:39 Error SyntaxError: Unexpected token 'struct'. */ +/* @@? 16:39 Error TypeError: Structs are only used to define UI components, it should be translated at 'plugin after parser' phase. */ /* @@? 17:5 Error SyntaxError: There is no any node to insert at the placeholder position. */ -/* @@? 17:7 Error TypeError: Unresolved reference Stave */ +/* @@? 17:5 Error SyntaxError: Unexpected token '@@'. */ +/* @@? 17:12 Error SyntaxError: Field type annotation expected. */ diff --git a/ets2panda/test/ast/compiler/ets/without_semicolon_before_struct_declaration.ets b/ets2panda/test/ast/compiler/ets/without_semicolon_before_struct_declaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..95aac85f2fe82d954f73743e8945375749c84ccc --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/without_semicolon_before_struct_declaration.ets @@ -0,0 +1,22 @@ +/* + * 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 x: number = 1; +const y: number = x +struct C { + f: number = 1; +} + +/* @@? 18:1 Error TypeError: Structs are only used to define UI components, it should be translated at 'plugin after parser' phase. */ \ No newline at end of file diff --git a/ets2panda/test/ast/parser/ets/annotations_tests/annotationDecl_parser_bad_token04.ets b/ets2panda/test/ast/parser/ets/annotations_tests/annotationDecl_parser_bad_token04.ets index 88cfdb4017c6ae03aa5e3c0e1528447d239f0ba0..21d016f414d88fec5654f578d80e1fa95fb1f85f 100644 --- a/ets2panda/test/ast/parser/ets/annotations_tests/annotationDecl_parser_bad_token04.ets +++ b/ets2panda/test/ast/parser/ets/annotations_tests/annotationDecl_parser_bad_token04.ets @@ -19,7 +19,4 @@ import * as Src from "./annotation_export" Src.MyAnno class /* @@ label */A/* @@ label1 */{} -/* @@? 19:1 Error TypeError: Class literal is not yet supported. */ -/* @@? 20:21 Error SyntaxError: Unexpected token 'A'. */ -/* @@? 20:21 Error TypeError: Unresolved reference A */ -/* @@? 20:37 Error SyntaxError: Unexpected token '{'. */ +/* @@? 19:5 Error TypeError: Property 'MyAnno' does not exist on type 'annotation_export' */ diff --git a/ets2panda/test/ast/parser/ets/class_keyword.ets b/ets2panda/test/ast/parser/ets/class_keyword.ets index f34d001a8c3e3270a960406e2c941dfabda5c726..93b3062592e6a82a9602391d9a7253617865f5ef 100644 --- a/ets2panda/test/ast/parser/ets/class_keyword.ets +++ b/ets2panda/test/ast/parser/ets/class_keyword.ets @@ -13,13 +13,10 @@ * limitations under the License. */ -final /* @@ label */kngkgj class /* @@ label1 */B /* @@ label2 */{ +final kngkgj class B { } -/* @@@ label Error SyntaxError: Unexpected token 'kngkgj'. */ -/* @@? 16:21 Error TypeError: Cannot find type 'kngkgj'. */ -/* @@? 16:21 Error TypeError: Class literal is not yet supported. */ -/* @@@ label1 Error SyntaxError: Unexpected token 'B'. */ -/* @@? 16:49 Error TypeError: Unresolved reference B */ -/* @@@ label2 Error SyntaxError: Unexpected token '{'. */ +/* @@? 16:7 Error SyntaxError: Unexpected token 'kngkgj'. */ +/* @@? 16:7 Error TypeError: Unresolved reference kngkgj */ +/* @@? 16:14 Error SyntaxError: Unexpected token 'class'. */ 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 050fbd6b1ca67ec270824aea69dac851a54d5283..692ad1e69d4ade9781d63df8f98de9e965764e3d 100644 --- a/ets2panda/test/ast/parser/ets/interface_parser_error_1.ets +++ b/ets2panda/test/ast/parser/ets/interface_parser_error_1.ets @@ -47,24 +47,17 @@ function mdin() { let a = new A(); /* @@? 20:16 Error SyntaxError: Unexpected token, expected ','. */ /* @@? 20:16 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ /* @@? 21:1 Error SyntaxError: Identifier expected. */ -/* @@? 22:1 Error TypeError: Class literal is not yet supported. */ -/* @@? 22:1 Error TypeError: Cannot find type 'inter'. */ -/* @@? 24:7 Error SyntaxError: Unexpected token 'A'. */ -/* @@? 24:7 Error TypeError: Unresolved reference A */ -/* @@? 24:9 Error SyntaxError: Unexpected token 'implements'. */ -/* @@? 24:20 Error SyntaxError: Unexpected token 'I'. */ -/* @@? 24:20 Error TypeError: Unresolved reference I */ -/* @@? 24:22 Error SyntaxError: Unexpected token '{'. */ -/* @@? 25:4 Error TypeError: Unresolved reference reanstructor */ -/* @@? 26:19 Error SyntaxError: Unexpected token, expected an identifier. */ +/* @@? 22:1 Error TypeError: Unresolved reference inter */ +/* @@? 24:1 Error SyntaxError: Illegal start of CLASS expression. */ /* @@? 26:19 Error SyntaxError: Unexpected token '�ls'. */ +/* @@? 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:5 Error SyntaxError: Hard keyword 'constructor' cannot be used as identifier */ /* @@? 28:16 Error SyntaxError: Invalid annotation name. */ /* @@? 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. */ -/* @@? 71:1 Error SyntaxError: Expected '}', got 'end of stream'. */ +/* @@? 64:1 Error SyntaxError: Expected '}', got 'end of stream'. */ diff --git a/ets2panda/test/runtime/ets/without_semicolon_before_class_declaration.ets b/ets2panda/test/runtime/ets/without_semicolon_before_class_declaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..63217805dd7c9eeab885f5dd026308f9cbaffe5b --- /dev/null +++ b/ets2panda/test/runtime/ets/without_semicolon_before_class_declaration.ets @@ -0,0 +1,26 @@ +/* + * 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 x: number = 1; +const y: number = x +class C { + foo(a: Int): Int { + return a; + } +} + +function main(): void { + arktest.assertEQ(new C().foo(1), 1) +} \ No newline at end of file