From d7b275569a4fff3f64d259944af70945d3d04b01 Mon Sep 17 00:00:00 2001 From: Tamas Toth Date: Thu, 22 May 2025 13:19:52 +0200 Subject: [PATCH] Fix re-exporting from the same file causes crash Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/IC9UW9 Fixes #25365 internal issue Signed-off-by: Tamas Toth Change-Id: Ibb676432bea6d89eba217e5fcdbb33ae5c786495 --- ets2panda/parser/ETSparser.cpp | 4 ++++ .../ets/re_export/re_export_circular.ets | 18 ++++++++++++++++++ ets2panda/util/diagnostic/syntax.yaml | 4 ++++ 3 files changed, 26 insertions(+) create mode 100644 ets2panda/test/ast/parser/ets/re_export/re_export_circular.ets diff --git a/ets2panda/parser/ETSparser.cpp b/ets2panda/parser/ETSparser.cpp index 33176a5cc1..f174d7506c 100644 --- a/ets2panda/parser/ETSparser.cpp +++ b/ets2panda/parser/ETSparser.cpp @@ -1082,6 +1082,10 @@ ir::Statement *ETSParser::ParseExport(lexer::SourcePosition startLoc, ir::Modifi } // re-export directive auto *reExportDeclaration = ParseImportPathBuildImport(std::move(specifiers), true, startLoc, ir::ImportKinds::ALL); + if (GetProgram()->AbsoluteName().Is(reExportDeclaration->ResolvedSource())) { + LogError(diagnostic::RE_EXPORTING_LOCAL_BINDINGS_IS_NOT_ALLOWED, {}, startLoc); + return AllocBrokenStatement(startLoc); + } auto reExport = AllocNode(reExportDeclaration, std::vector(), GetProgram()->AbsoluteName(), Allocator()); reExport->AddModifier(modifiers); diff --git a/ets2panda/test/ast/parser/ets/re_export/re_export_circular.ets b/ets2panda/test/ast/parser/ets/re_export/re_export_circular.ets new file mode 100644 index 0000000000..bfc5c191e6 --- /dev/null +++ b/ets2panda/test/ast/parser/ets/re_export/re_export_circular.ets @@ -0,0 +1,18 @@ +/* + * 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. + */ + +export {foo} from "./re_export_circular.ets" + +/* @@? 16:8 Error SyntaxError: Re-exporting local bindings is not allowed */ diff --git a/ets2panda/util/diagnostic/syntax.yaml b/ets2panda/util/diagnostic/syntax.yaml index fef5d62ff2..8d840c7013 100644 --- a/ets2panda/util/diagnostic/syntax.yaml +++ b/ets2panda/util/diagnostic/syntax.yaml @@ -1287,3 +1287,7 @@ syntax: - name: FUNC_EXPR id: 320 message: "Function expressions are not supported, use arrow functions instead" + +- name: RE_EXPORTING_LOCAL_BINDINGS_IS_NOT_ALLOWED + id: 321 + message: "Re-exporting local bindings is not allowed" -- Gitee