From 6ffad273c69c7810c963bdda683c2f8376b883a7 Mon Sep 17 00:00:00 2001 From: "peter.pronai" Date: Mon, 26 May 2025 10:12:58 +0000 Subject: [PATCH] Add diagnostic for generator function Fixes #24865 internal issue. Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICAN1E Change-Id: I20ec5b7c6913daa641cefb82545d50f438bd8ec2 Signed-off-by: peter.pronai --- ets2panda/parser/ETSparser.cpp | 1 + .../test/ast/parser/ets/generator_function.ets | 17 +++++++++++++++++ ets2panda/util/diagnostic/syntax.yaml | 6 +++++- 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 ets2panda/test/ast/parser/ets/generator_function.ets diff --git a/ets2panda/parser/ETSparser.cpp b/ets2panda/parser/ETSparser.cpp index 6a1ca88c8b..99bbca1b39 100644 --- a/ets2panda/parser/ETSparser.cpp +++ b/ets2panda/parser/ETSparser.cpp @@ -2049,6 +2049,7 @@ ir::FunctionDeclaration *ETSParser::ParseFunctionDeclaration(bool canBeAnonymous } if (Lexer()->TryEatTokenType(lexer::TokenType::PUNCTUATOR_MULTIPLY)) { + LogError(diagnostic::GENERATOR_FUNCTION); newStatus |= ParserStatus::GENERATOR_FUNCTION; } diff --git a/ets2panda/test/ast/parser/ets/generator_function.ets b/ets2panda/test/ast/parser/ets/generator_function.ets new file mode 100644 index 0000000000..7f865bb644 --- /dev/null +++ b/ets2panda/test/ast/parser/ets/generator_function.ets @@ -0,0 +1,17 @@ +/** + * 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* f() {} +/* @@? 16:11 Error SyntaxError: Generator functions are not supported, please use async/await mechanism for multitasking */ diff --git a/ets2panda/util/diagnostic/syntax.yaml b/ets2panda/util/diagnostic/syntax.yaml index a412c35ab5..47f5f4608b 100644 --- a/ets2panda/util/diagnostic/syntax.yaml +++ b/ets2panda/util/diagnostic/syntax.yaml @@ -1230,4 +1230,8 @@ syntax: - name: DEEP_NESTING id: 305 - message: "Maximum allowed nesting level exceeded." \ No newline at end of file + message: "Maximum allowed nesting level exceeded." + +- name: GENERATOR_FUNCTION + id: 306 + message: "Generator functions are not supported, please use async/await mechanism for multitasking" -- Gitee