diff --git a/ets2panda/compiler/lowering/ets/unboxLowering.cpp b/ets2panda/compiler/lowering/ets/unboxLowering.cpp index 6cbc281cf1a985e303c02ee2cb2dbdcfad06e3e1..b33a59d270584c698ec77ae62812a7015fb7b121 100644 --- a/ets2panda/compiler/lowering/ets/unboxLowering.cpp +++ b/ets2panda/compiler/lowering/ets/unboxLowering.cpp @@ -25,6 +25,7 @@ #include "compiler/lowering/util.h" #include "util/es2pandaMacros.h" #include "generated/signatures.h" +#include "util/helpers.h" namespace ark::es2panda::compiler { @@ -251,8 +252,8 @@ static void HandleScriptFunctionHeader(UnboxContext *uctx, ir::ScriptFunction *f // Special case for primitive `valueOf` functions -- should still return boxed values (used in codegen) if (func->Parent()->Parent()->IsMethodDefinition() && func->Parent()->Parent()->AsMethodDefinition()->Id()->Name() == "valueOf" && - ContainingClass(func)->AsETSObjectType()->IsBoxedPrimitive() && sig->Params().size() == 1 && - !sig->Params()[0]->TsType()->IsETSEnumType()) { + util::Helpers::GetContainingObjectType(func)->AsETSObjectType()->IsBoxedPrimitive() && + sig->Params().size() == 1) { auto *boxed = func->Parent()->Parent()->Parent()->AsTyped()->TsType(); auto *unboxed = MaybeRecursivelyUnboxType(uctx, boxed); diff --git a/ets2panda/test/runtime/ets/valueof_name_collision.ets b/ets2panda/test/runtime/ets/valueof_name_collision.ets new file mode 100644 index 0000000000000000000000000000000000000000..a46a9d5749a3653c992a749cbe04521753420dc7 --- /dev/null +++ b/ets2panda/test/runtime/ets/valueof_name_collision.ets @@ -0,0 +1,23 @@ +/* + * 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. + */ + +interface Inter { + valueOf : number; +} + +function main() { + let inter : Inter = { valueOf: 10}; + arktest.assertEQ(inter.valueOf, 10); +}