diff --git a/ets2panda/parser/ETSparserExpressions.cpp b/ets2panda/parser/ETSparserExpressions.cpp index 9b7dc49103daa67de0f5e3c03725d6d4bc6683ce..5ad55ecac79de9ce0a91795637bb159d88bdf0ce 100644 --- a/ets2panda/parser/ETSparserExpressions.cpp +++ b/ets2panda/parser/ETSparserExpressions.cpp @@ -311,8 +311,14 @@ ir::Expression *ETSParser::ParseDefaultPrimaryExpression(ExpressionParseFlags fl ir::TypeNode *potentialType = ParseTypeAnnotation(&options); if (potentialType != nullptr) { + // #29702 remove special handling for TSArray. if (potentialType->IsTSArrayType()) { - return potentialType; + auto currentSavedPos = Lexer()->Save(); + Lexer()->Rewind(savedPos); + const auto tokenNow = Lexer()->GetToken(); + LogUnexpectedToken(tokenNow); + Lexer()->Rewind(currentSavedPos); + return AllocBrokenExpression(tokenNow.Loc()); } if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_PERIOD) { diff --git a/ets2panda/test/ast/compiler/ets/array_type_as_param.ets b/ets2panda/test/ast/compiler/ets/array_type_as_param.ets new file mode 100644 index 0000000000000000000000000000000000000000..b8f173ad201c7128f7ec9d9c9a738b34b44f6811 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/array_type_as_param.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. + */ + +function foo(a:number[]){ + +} + +function main(){ + foo(typeof number[]) + foo(number[]) +} + +/* @@? 21:16 Error SyntaxError: Unexpected token 'number'. */ +/* @@? 22:9 Error SyntaxError: Unexpected token 'number'. */ \ No newline at end of file diff --git a/ets2panda/test/ast/compiler/ets/array_type_as_value.ets b/ets2panda/test/ast/compiler/ets/array_type_as_value.ets new file mode 100644 index 0000000000000000000000000000000000000000..20dbca68adef30f2cdd781b94fd59efa3e08763b --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/array_type_as_value.ets @@ -0,0 +1,33 @@ +/* + * 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. + */ + +class A {a0 : number[] = []} + +function main(){ + let v1 = [number[]] + let v2 : A = {a0: number[]} + if(Int[]){} + while(number[]){} + let v3 = int[] && true + let v4 = long[] || false +} + +/* @@? 19:15 Error SyntaxError: Unexpected token 'number'. */ +/* @@? 20:23 Error SyntaxError: Unexpected token 'number'. */ +/* @@? 21:8 Error SyntaxError: Unexpected token 'Int'. */ +/* @@? 22:11 Error SyntaxError: Unexpected token 'number'. */ +/* @@? 23:5 Error SyntaxError: Missing condition in while statement */ +/* @@? 23:14 Error SyntaxError: Unexpected token 'int'. */ +/* @@? 24:14 Error SyntaxError: Unexpected token 'long'. */ \ No newline at end of file diff --git a/ets2panda/test/ast/compiler/ets/type_as_value.ets b/ets2panda/test/ast/compiler/ets/type_as_value.ets index 2fdb848aaef88b463c0cb23c3ad397fee714d7a1..fb69b217cc56efed69c8c6f0e06d7c424c79a45c 100644 --- a/ets2panda/test/ast/compiler/ets/type_as_value.ets +++ b/ets2panda/test/ast/compiler/ets/type_as_value.ets @@ -15,4 +15,4 @@ let a = number[][] -/* @@? 16:17 Error TypeError: 'Array>' only refers to a type, but is being used as a value here. */ \ No newline at end of file +/* @@? 16:9 Error SyntaxError: Unexpected token 'number'. */ \ No newline at end of file diff --git a/ets2panda/test/ast/parser/ets/MultipleParserErrors.ets b/ets2panda/test/ast/parser/ets/MultipleParserErrors.ets index 257ff2bd18f6d3494ee020147d6c318bb66eeab7..6e6cf94a8ebe33e7f67bf56d675350b0c6b34637 100644 --- a/ets2panda/test/ast/parser/ets/MultipleParserErrors.ets +++ b/ets2panda/test/ast/parser/ets/MultipleParserErrors.ets @@ -198,6 +198,7 @@ function main(): void { /* @@? 51:25 Error SyntaxError: Rest parameter must be the last formal parameter. */ /* @@? 51:27 Error SyntaxError: Unexpected token '...'. */ /* @@? 51:30 Error SyntaxError: Unexpected token 'p'. */ +/* @@? 51:33 Error SyntaxError: Unexpected token 'int'. */ /* @@? 51:33 Error SyntaxError: Label must be followed by a loop statement. */ /* @@? 51:38 Error SyntaxError: Unexpected token ')'. */ /* @@? 51:39 Error SyntaxError: Unexpected token ':'. */ @@ -288,4 +289,4 @@ function main(): void { /* @@? 165:5 Error TypeError: This expression is not callable. */ /* @@? 166:5 Error TypeError: No matching call signature */ /* @@? 166:5 Error TypeError: Expected 1 arguments, got 0. */ -/* @@? 292:1 Error SyntaxError: Expected '}', got 'end of stream'. */ +/* @@? 293:1 Error SyntaxError: Expected '}', got 'end of stream'. */ diff --git a/ets2panda/test/ast/parser/ets/readonlyFunctionTypeAnnotation.ets b/ets2panda/test/ast/parser/ets/readonlyFunctionTypeAnnotation.ets index 686f313ee070e7f322ff87ed868b7a484d8be38d..5b7703cef0ba2ece77c997481bd4f0d625a0c257 100644 --- a/ets2panda/test/ast/parser/ets/readonlyFunctionTypeAnnotation.ets +++ b/ets2panda/test/ast/parser/ets/readonlyFunctionTypeAnnotation.ets @@ -22,6 +22,6 @@ func: readonly (Y : object | long [] ) => [ ] /* @@? 17:20 Error SyntaxError: Unexpected token ':'. */ /* @@? 17:22 Error SyntaxError: Unexpected token 'object'. */ /* @@? 17:22 Error TypeError: Type name 'object' used in the wrong context */ -/* @@? 17:22 Error TypeError: Bad operand type, the types of the operands must be numeric type. */ +/* @@? 17:31 Error SyntaxError: Unexpected token 'long'. */ /* @@? 17:39 Error SyntaxError: Unexpected token ')'. */ /* @@? 17:42 Error SyntaxError: Unexpected token '=>'. */ \ No newline at end of file diff --git a/ets2panda/test/ast/parser/ets/unexpected_token_38.ets b/ets2panda/test/ast/parser/ets/unexpected_token_38.ets index 780e05d9629c60f9001974f4d2513e40cda83429..cf3bc0a1d1e7042f4be2f7e0befb1cd0e1697c59 100644 --- a/ets2panda/test/ast/parser/ets/unexpected_token_38.ets +++ b/ets2panda/test/ast/parser/ets/unexpected_token_38.ets @@ -28,4 +28,3 @@ let func3: (f: (a: number, b: string) => number[]): number[] => (a: number, b: b /* @@? 22:51 Error SyntaxError: Unexpected token '=>'. */ /* @@? 22:53 Error SyntaxError: Unexpected token 'number'. */ /* @@? 22:62 Error SyntaxError: Unexpected token '=>'. */ -/* @@? 22:62 Error SyntaxError: Unexpected token. */