From a9378fd5cb1a212cace0069f9f951c35f3ab9d6a Mon Sep 17 00:00:00 2001 From: anjiaqi Date: Fri, 5 Sep 2025 16:23:18 +0800 Subject: [PATCH] fix failure call of UpperAndLower method on char Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICWLY3 Signed-off-by: anjiaqi --- .../lowering/ets/primitiveConversionPhase.cpp | 7 +++--- .../test/runtime/ets/toUpper_toLower_case.ets | 23 +++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 ets2panda/test/runtime/ets/toUpper_toLower_case.ets diff --git a/ets2panda/compiler/lowering/ets/primitiveConversionPhase.cpp b/ets2panda/compiler/lowering/ets/primitiveConversionPhase.cpp index 7a27a2001b..5cc70c34e1 100644 --- a/ets2panda/compiler/lowering/ets/primitiveConversionPhase.cpp +++ b/ets2panda/compiler/lowering/ets/primitiveConversionPhase.cpp @@ -69,13 +69,14 @@ static ir::Expression *ConvertCallIfNeeded(public_lib::Context *ctx, ir::CallExp return call; } - /* Now that we know that we deal with a conversion call, replace it with a static call, - except that when the call is `x.toX()`, we can just return `x`. + /* When the conversion call is `x.toX()` or `y.toX()`, replace it with `x` or a static call, but when the `x` is + charType we cannot just replace `x.toX()` with `x`, because when we call the builtin method `x.toUpperCase()` and + `x.toLowerCase()`, we need replace them with static call too. */ auto *allocator = ctx->Allocator(); - if (checker->Relation()->IsIdenticalTo(calleeObjType, call->TsType())) { + if (!calleeObjType->IsETSCharType() && checker->Relation()->IsIdenticalTo(calleeObjType, call->TsType())) { calleeObj->SetParent(call->Parent()); return calleeObj; } diff --git a/ets2panda/test/runtime/ets/toUpper_toLower_case.ets b/ets2panda/test/runtime/ets/toUpper_toLower_case.ets new file mode 100644 index 0000000000..1768bf6f55 --- /dev/null +++ b/ets2panda/test/runtime/ets/toUpper_toLower_case.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023-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. + */ + +function main() { + let x1: Char = c'a' + let res1 = x1.toUpperCase(); + let x2: Char = c'A' + let res2 = x2.toLowerCase(); + arktest.assertEQ(res1, c'A') + arktest.assertEQ(res2, c'a') +} \ No newline at end of file -- Gitee