From 3fa52a8f657fa32d23c0ab12830159d45a462bc6 Mon Sep 17 00:00:00 2001 From: fcc Date: Fri, 20 Jun 2025 17:20:44 +0800 Subject: [PATCH] fix instantiate void parameter type After instantiation, parameter type might be 'void'. Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICGPYZ Signed-off-by: fcc --- ets2panda/checker/types/signature.cpp | 4 ++++ ets2panda/test/runtime/ets/voidTypeArg.ets | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/ets2panda/checker/types/signature.cpp b/ets2panda/checker/types/signature.cpp index 5ced79c411..4533d51d30 100644 --- a/ets2panda/checker/types/signature.cpp +++ b/ets2panda/checker/types/signature.cpp @@ -51,6 +51,10 @@ Signature *Signature::Substitute(TypeRelation *relation, const Substitution *sub if (newParamType != param->TsType()) { anyChange = true; newParam = param->Copy(allocator, param->Declaration()); + if (newParamType->IsETSVoidType()) { + // since `void` is not allowed to be used as param type + newParamType = checker->GlobalETSUndefinedType(); + } newParam->SetTsType(newParamType); } newSigInfo->params.push_back(newParam); diff --git a/ets2panda/test/runtime/ets/voidTypeArg.ets b/ets2panda/test/runtime/ets/voidTypeArg.ets index 66c7cee2db..e9367a44f6 100644 --- a/ets2panda/test/runtime/ets/voidTypeArg.ets +++ b/ets2panda/test/runtime/ets/voidTypeArg.ets @@ -17,9 +17,17 @@ function foo(a0: T): T { return a0; } +type Fn = (e: T) => void; + +function test(arg: Fn) {} + function main() : void { foo(undefined); let bfoo = foo(undefined); arktest.assertEQ(bfoo, undefined) + + test((e) => { + arktest.assertEQ(e, undefined) + }) } -- Gitee