From 0b13a066e14eb853a08e339a7a0db3924be6ff52 Mon Sep 17 00:00:00 2001 From: likaizheng Date: Fri, 12 Sep 2025 15:58:08 +0800 Subject: [PATCH] FIX unbox enum long to primitive in unary ops Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICXQLF Signed-off-by: likaizheng --- ets2panda/checker/ets/helpers.cpp | 3 +- .../test/runtime/ets/long_enum_unary.ets | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 ets2panda/test/runtime/ets/long_enum_unary.ets diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index dd5d023d62..8a8ad698f0 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -443,7 +443,8 @@ Type *ETSChecker::ApplyUnaryOperatorPromotion(ir::Expression *expr, Type *type, [[fallthrough]]; case TypeFlag::INT: return GlobalIntBuiltinType(); - + case TypeFlag::LONG: + return GlobalLongBuiltinType(); default: break; } diff --git a/ets2panda/test/runtime/ets/long_enum_unary.ets b/ets2panda/test/runtime/ets/long_enum_unary.ets new file mode 100644 index 0000000000..1ade249bed --- /dev/null +++ b/ets2panda/test/runtime/ets/long_enum_unary.ets @@ -0,0 +1,30 @@ +/* + * 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. + */ + +enum LongEnum{ + Neg = -0x1_1111_1111, + Pos = 0x1_1111_1111, + Min = -923372036854775808, + Max = 923372036854775808 + +} + +function main() : void { + let l = +LongEnum.Neg + arktest.assertEQ(+LongEnum.Min,LongEnum.Min) + arktest.assertEQ(+LongEnum.Max,LongEnum.Max) + arktest.assertEQ(+LongEnum.Neg,LongEnum.Neg) + arktest.assertEQ(+LongEnum.Pos,LongEnum.Pos) +} \ No newline at end of file -- Gitee