From f554102dcc2bb5bbd96a717801e3c3c3f8d8afeb Mon Sep 17 00:00:00 2001 From: gizembusraturan Date: Wed, 27 Aug 2025 16:51:11 +0300 Subject: [PATCH] Title: exported function Issue: ICTOF8 Testing: Build Signed-off-by: gizembusraturan --- ets2panda/checker/ets/object.cpp | 7 +------ ets2panda/checker/ets/typeCheckingHelpers.cpp | 6 ++++++ .../compiler/ets/first_match/namespace.ets | 3 +++ .../compiler/ets/overload/export_function.ets | 21 +++++++++++++++++++ .../compiler/ets/overload}/namespace5.ets | 4 +--- .../compiler/ets/overload}/native_method.ets | 6 +++--- .../overload_overloaded_method_exported.ets | 3 +++ ets2panda/util/diagnostic/semantic.yaml | 6 +++++- 8 files changed, 43 insertions(+), 13 deletions(-) create mode 100644 ets2panda/test/ast/compiler/ets/overload/export_function.ets rename ets2panda/test/{runtime/ets/first_match => ast/compiler/ets/overload}/namespace5.ets (88%) rename ets2panda/test/{runtime/ets/first_match => ast/compiler/ets/overload}/native_method.ets (88%) diff --git a/ets2panda/checker/ets/object.cpp b/ets2panda/checker/ets/object.cpp index d371eac06c..388d4898c4 100644 --- a/ets2panda/checker/ets/object.cpp +++ b/ets2panda/checker/ets/object.cpp @@ -90,14 +90,9 @@ static bool CheckGetterSetterDecl(varbinder::LocalVariable const *child, varbind static bool CheckOverloadDecl(varbinder::LocalVariable *child, varbinder::LocalVariable *parent) { - if (!child->Declaration()->Node()->IsOverloadDeclaration() && - !parent->Declaration()->Node()->IsOverloadDeclaration()) { - return false; - } - if (!child->Declaration()->Node()->IsOverloadDeclaration() || !parent->Declaration()->Node()->IsOverloadDeclaration()) { - return true; + return false; } auto *childOverload = child->Declaration()->Node()->AsOverloadDeclaration(); diff --git a/ets2panda/checker/ets/typeCheckingHelpers.cpp b/ets2panda/checker/ets/typeCheckingHelpers.cpp index 6f0a218600..367c45f104 100644 --- a/ets2panda/checker/ets/typeCheckingHelpers.cpp +++ b/ets2panda/checker/ets/typeCheckingHelpers.cpp @@ -1706,6 +1706,12 @@ static bool CheckAccessModifierForOverloadDeclaration(ETSChecker *const checker, return false; } + if ((overLoadAliasFlags & ir::ModifierFlags::EXPORT) != 0 && + (overloadedMethodFlags & ir::ModifierFlags::EXPORT) == 0) { + checker->LogError(diagnostic::OVERLOADED_NAME_MUST_ALSO_EXPORTED, {}, pos); + return false; + } + return true; } diff --git a/ets2panda/test/ast/compiler/ets/first_match/namespace.ets b/ets2panda/test/ast/compiler/ets/first_match/namespace.ets index 562555e43f..38ba6b5ba0 100644 --- a/ets2panda/test/ast/compiler/ets/first_match/namespace.ets +++ b/ets2panda/test/ast/compiler/ets/first_match/namespace.ets @@ -61,6 +61,9 @@ function main(){ NS.overloadfoo3("abc"); } +/* @@? 25:34 Error TypeError: Overload alias is exported, then overload functions must also be exported. */ +/* @@? 25:40 Error TypeError: Overload alias is exported, then overload functions must also be exported. */ +/* @@? 35:41 Error TypeError: Overload alias is exported, then overload functions must also be exported. */ /* @@? 49:8 Error TypeError: 'foo1' is not exported in 'NS' */ /* @@? 50:8 Error TypeError: 'foo2' is not exported in 'NS' */ /* @@? 52:8 Error TypeError: 'foo4' is not exported in 'NS' */ diff --git a/ets2panda/test/ast/compiler/ets/overload/export_function.ets b/ets2panda/test/ast/compiler/ets/overload/export_function.ets new file mode 100644 index 0000000000..e46cffd769 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/overload/export_function.ets @@ -0,0 +1,21 @@ +/* + * 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 function foo1(p: string) {} +function foo2(p: number) {} +export overload foo { foo1, foo2 } +overload bar { foo1, foo2 } + +/* @@? 18:29 Error TypeError: Overload alias is exported, then overload functions must also be exported. */ \ No newline at end of file diff --git a/ets2panda/test/runtime/ets/first_match/namespace5.ets b/ets2panda/test/ast/compiler/ets/overload/namespace5.ets similarity index 88% rename from ets2panda/test/runtime/ets/first_match/namespace5.ets rename to ets2panda/test/ast/compiler/ets/overload/namespace5.ets index b7d53c5871..78c0eea279 100644 --- a/ets2panda/test/runtime/ets/first_match/namespace5.ets +++ b/ets2panda/test/ast/compiler/ets/overload/namespace5.ets @@ -25,6 +25,4 @@ namespace NS { export overload overloadfoo{ foo1, foo2 } } -function main() { - arktest.assertEQ(NS.overloadfoo(1), "invoke1"); -} +/* @@? 25:40 Error TypeError: Overload alias is exported, then overload functions must also be exported. */ \ No newline at end of file diff --git a/ets2panda/test/runtime/ets/first_match/native_method.ets b/ets2panda/test/ast/compiler/ets/overload/native_method.ets similarity index 88% rename from ets2panda/test/runtime/ets/first_match/native_method.ets rename to ets2panda/test/ast/compiler/ets/overload/native_method.ets index 82c3e1e60f..debc08266e 100644 --- a/ets2panda/test/runtime/ets/first_match/native_method.ets +++ b/ets2panda/test/ast/compiler/ets/overload/native_method.ets @@ -37,7 +37,7 @@ overload foo{ foo1, foo2 } function main() { let a = new A(); - arktest.assertEQ(a.foo("abc"), "invoke1"); - arktest.assertEQ(NS.foo("abc"), "invoke2"); - arktest.assertEQ(foo("abc"), "invoke3"); } + + +/* @@? 29:26 Error TypeError: Overload alias is exported, then overload functions must also be exported. */ \ No newline at end of file diff --git a/ets2panda/test/ast/compiler/ets/overload/overload_overloaded_method_exported.ets b/ets2panda/test/ast/compiler/ets/overload/overload_overloaded_method_exported.ets index 1510e3ff40..5ae8220475 100644 --- a/ets2panda/test/ast/compiler/ets/overload/overload_overloaded_method_exported.ets +++ b/ets2panda/test/ast/compiler/ets/overload/overload_overloaded_method_exported.ets @@ -16,3 +16,6 @@ export function foo1() {} function foo2() {} export overload foo {foo1, foo2} + + +/* @@? 18:28 Error TypeError: Overload alias is exported, then overload functions must also be exported. */ \ No newline at end of file diff --git a/ets2panda/util/diagnostic/semantic.yaml b/ets2panda/util/diagnostic/semantic.yaml index 53aa40aaeb..44df4a81b8 100644 --- a/ets2panda/util/diagnostic/semantic.yaml +++ b/ets2panda/util/diagnostic/semantic.yaml @@ -1026,6 +1026,10 @@ semantic: id: 307 message: "Overloaded method is used as value" +- name: OVERLOADED_NAME_MUST_ALSO_EXPORTED + id: 148271 + message: "Overload alias is exported, then overload functions must also be exported." + - name: OVERLOADED_NAME_MUST_FUNCTION id: 384 message: "overloaded name must refer to an accessible method." @@ -1405,7 +1409,7 @@ semantic: - name: UNRESOLVED_REF id: 143 message: "Unresolved reference {}" - code_fix_ids: [FixSpelling,AddLocalVariable] + code_fix_ids: [FixSpelling, AddLocalVariable] - name: UNSUPPORTED_CLASS_LITERAL id: 20 -- Gitee