diff --git a/ets2panda/compiler/core/ETSemitter.cpp b/ets2panda/compiler/core/ETSemitter.cpp index f4f15ac06c0d8fadfcb50969c7e52475a67567de..5a8eb413b34e7c69f5a947b9b1855b627411fb45 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 0000000000000000000000000000000000000000..915efd07351db1cc8ab4fb9df8d57f11ef534eb1 --- /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 0000000000000000000000000000000000000000..e238e0fb4d95704e35d0b3e1c2bc5491641b797c --- /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();