diff --git a/ets2panda/parser/ETSparserStatements.cpp b/ets2panda/parser/ETSparserStatements.cpp index 0b8fc5d913c0f2c867bf736981280e7a1a63ff8f..1665d4b1a5c000d98762826dbf2048f0f9f46c6e 100644 --- a/ets2panda/parser/ETSparserStatements.cpp +++ b/ets2panda/parser/ETSparserStatements.cpp @@ -323,7 +323,7 @@ bool ETSParser::ValidateLabeledStatement(lexer::TokenType type) bool ETSParser::ValidateForInStatement() { - LogUnexpectedToken(lexer::TokenType::KEYW_IN); + LogError(diagnostic::ERROR_ARKTS_NO_FOR_IN_LOOP); return false; } diff --git a/ets2panda/test/ast/parser/ets/FixedArray/InvalidStatements3.ets b/ets2panda/test/ast/parser/ets/FixedArray/InvalidStatements3.ets index 29c5aced21a30e34d933b5f39f6f9a22d678e5e1..ef5fb160524f486bcf001ae132a3c0868e648940 100644 --- a/ets2panda/test/ast/parser/ets/FixedArray/InvalidStatements3.ets +++ b/ets2panda/test/ast/parser/ets/FixedArray/InvalidStatements3.ets @@ -60,4 +60,4 @@ for (let i = 1 in [0, 1, 2]) {} /* @@? 38:13 Error SyntaxError: Unexpected token '@'. */ /* @@? 38:14 Error TypeError: Cannot find type 'annotate'. */ /* @@? 42:16 Error SyntaxError: for-in loop variable declaration may not have an initializer. */ -/* @@? 42:16 Error SyntaxError: Unexpected token 'in'. */ +/* @@? 42:16 Error SyntaxError: 'for ... in' loop is not supported, please use regular 'for' or 'for ... of ...' loop to iterate through arrays and iterable objects. */ diff --git a/ets2panda/test/ast/parser/ets/InvalidStatements3.ets b/ets2panda/test/ast/parser/ets/InvalidStatements3.ets index 85b2082bf489c9042642d5a0d34628fbc8c180d6..308ab7542c9dc3dca8077fb5dfc665065e625eba 100644 --- a/ets2panda/test/ast/parser/ets/InvalidStatements3.ets +++ b/ets2panda/test/ast/parser/ets/InvalidStatements3.ets @@ -55,9 +55,9 @@ for (let i = 1 in [0, 1, 2]) {} /* @@? 31:9 Error SyntaxError: Unexpected token 'let'. */ /* @@? 31:13 Error SyntaxError: Unexpected token 'x'. */ /* @@? 34:5 Error SyntaxError: Illegal 'use strict' directive in function with non-simple parameter list. */ -/* @@? 38:5 Error SyntaxError: Unexpected token 'private'. */ /* @@? 38:5 Error SyntaxError: Annotation declaration can not have access modifier. */ +/* @@? 38:5 Error SyntaxError: Unexpected token 'private'. */ /* @@? 38:13 Error SyntaxError: Unexpected token '@'. */ /* @@? 38:14 Error TypeError: Cannot find type 'annotate'. */ /* @@? 42:16 Error SyntaxError: for-in loop variable declaration may not have an initializer. */ -/* @@? 42:16 Error SyntaxError: Unexpected token 'in'. */ +/* @@? 42:16 Error SyntaxError: 'for ... in' loop is not supported, please use regular 'for' or 'for ... of ...' loop to iterate through arrays and iterable objects. */ diff --git a/ets2panda/test/ast/parser/ets/for_in.ets b/ets2panda/test/ast/parser/ets/for_in.ets new file mode 100644 index 0000000000000000000000000000000000000000..922bde17d5a79170a098ebc31071f129909015d2 --- /dev/null +++ b/ets2panda/test/ast/parser/ets/for_in.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 a: number[] = [1.0, 2.0, 3.0] +for (let i /* @@ label */in a) { +} + +/* @@@ label Error SyntaxError: Variable must be initialized or it's type must be declared. */ +/* @@@ label Error SyntaxError: 'for ... in' loop is not supported, please use regular 'for' or 'for ... of ...' loop to iterate through arrays + and iterable objects. */ diff --git a/ets2panda/util/diagnostic/syntax.yaml b/ets2panda/util/diagnostic/syntax.yaml index a998b7eacc637388b76862e1f7d1c186d3e43878..36dbf07b186320f8d648b0b52959039dbced5894 100644 --- a/ets2panda/util/diagnostic/syntax.yaml +++ b/ets2panda/util/diagnostic/syntax.yaml @@ -213,6 +213,11 @@ syntax: id: 307 message: "'export = ...' syntax is not supported, use regular import/export instead!" +- name: ERROR_ARKTS_NO_FOR_IN_LOOP + id: 6987 + message: "'for ... in' loop is not supported, please use regular 'for' or 'for ... of ...' loop to iterate through arrays + and iterable objects." + - name: ERROR_ARKTS_NO_IMPORT_ASSERTIONS id: 313 message: "Import assertion is not supported, please use the ordinary import syntax instead!"