From f51f8e89817981b6ae487cfebe7efe27e31c2a47 Mon Sep 17 00:00:00 2001 From: yp9522 Date: Mon, 14 Jul 2025 16:56:47 +0800 Subject: [PATCH] Fix record for exported 'this' return Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICVKDL Signed-off-by: yp9522 --- ets2panda/compiler/core/ETSemitter.cpp | 3 +++ .../ets/external_func_record/file1.ets | 17 +++++++++++++++++ .../ets/external_func_record/main_test.ets | 18 ++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100755 ets2panda/test/ast/compiler/ets/external_func_record/file1.ets create mode 100755 ets2panda/test/ast/compiler/ets/external_func_record/main_test.ets diff --git a/ets2panda/compiler/core/ETSemitter.cpp b/ets2panda/compiler/core/ETSemitter.cpp index f4f15ac06c..5a8eb413b3 100644 --- a/ets2panda/compiler/core/ETSemitter.cpp +++ b/ets2panda/compiler/core/ETSemitter.cpp @@ -137,6 +137,9 @@ static pandasm::Function GenScriptFunction(const ir::ScriptFunction *scriptFunc, if (scriptFunc->IsConstructor() || scriptFunc->IsStaticBlock()) { func.returnType = pandasm::Type(Signatures::PRIMITIVE_VOID, 0); + } else if (scriptFunc->Signature()->HasSignatureFlag(checker::SignatureFlags::THIS_RETURN_TYPE) && + scriptFunc->Signature()->HasSignatureFlag(checker::SignatureFlags::EXTENSION_FUNCTION)) { + func.returnType = PandasmTypeWithRank(paramScope->Params()[0]->TsType()); } else { func.returnType = PandasmTypeWithRank(scriptFunc->Signature()->ReturnType()); } diff --git a/ets2panda/test/ast/compiler/ets/external_func_record/file1.ets b/ets2panda/test/ast/compiler/ets/external_func_record/file1.ets new file mode 100755 index 0000000000..915efd0735 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/external_func_record/file1.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. + */ + +export class A {} +export function foo(this: A):this {return this} \ No newline at end of file diff --git a/ets2panda/test/ast/compiler/ets/external_func_record/main_test.ets b/ets2panda/test/ast/compiler/ets/external_func_record/main_test.ets new file mode 100755 index 0000000000..e238e0fb4d --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/external_func_record/main_test.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. + */ + +import {A, foo} from "./file1" +let a = new A(); +a.foo(); -- Gitee