From 0479953ac9f04c34fe87af8f3b3b918facb0d5f6 Mon Sep 17 00:00:00 2001 From: yp9522 Date: Mon, 14 Jul 2025 10:22:30 +0800 Subject: [PATCH] fix null_pointer issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICLREE Signed-off-by: yp9522 --- ets2panda/checker/ets/arithmetic.cpp | 7 ++++ .../test/ast/compiler/ets/intEnumOperand.ets | 33 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 ets2panda/test/ast/compiler/ets/intEnumOperand.ets diff --git a/ets2panda/checker/ets/arithmetic.cpp b/ets2panda/checker/ets/arithmetic.cpp index b76c779b5a..d0f6a2944c 100644 --- a/ets2panda/checker/ets/arithmetic.cpp +++ b/ets2panda/checker/ets/arithmetic.cpp @@ -1063,8 +1063,15 @@ static void TryAddValueOfFlagToStringEnumOperand(ir::Expression *op, const ir::E static void TryAddValueOfFlagToIntEnumOperand(ir::Expression *op, const ir::Expression *otherOp) { + if (op == nullptr || otherOp == nullptr) { + return; + } auto type = op->TsType(); auto otherType = otherOp->TsType(); + if (type == nullptr || otherType == nullptr) { + return; + } + if (type->IsETSIntEnumType() && ((otherType->IsETSObjectType() && otherType->AsETSObjectType()->IsBoxedPrimitive()) || otherType->IsETSIntEnumType())) { diff --git a/ets2panda/test/ast/compiler/ets/intEnumOperand.ets b/ets2panda/test/ast/compiler/ets/intEnumOperand.ets new file mode 100644 index 0000000000..f647326ec1 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/intEnumOperand.ets @@ -0,0 +1,33 @@ +/* +* 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. +*/ + +function main(): void { + let barArg = arg as Bar +* console.log(barArg.bar) +} + +/* @@? 17:18 Error TypeError: Bad operand type, the types of the operands must be numeric type. */ +/* @@? 17:25 Error TypeError: Cannot find type 'Bar'. */ +/* @@? 18:6 Error TypeError: Circular call function */ +/* @@? 18:6 Error TypeError: Call to `log` is ambiguous as `2` versions of `log` are available: `log(i: String): void` and `log(i: Boolean): void` */ +/* @@? 18:6 Error TypeError: Call to `log` is ambiguous as `2` versions of `log` are available: `log(i: String): void` and `log(i: Byte): void` */ +/* @@? 18:6 Error TypeError: Call to `log` is ambiguous as `2` versions of `log` are available: `log(i: String): void` and `log(i: Short): void` */ +/* @@? 18:6 Error TypeError: Call to `log` is ambiguous as `2` versions of `log` are available: `log(i: String): void` and `log(i: Char): void` */ +/* @@? 18:6 Error TypeError: Call to `log` is ambiguous as `2` versions of `log` are available: `log(i: String): void` and `log(i: Int): void` */ +/* @@? 18:6 Error TypeError: Call to `log` is ambiguous as `2` versions of `log` are available: `log(i: String): void` and `log(i: Long): void` */ +/* @@? 18:6 Error TypeError: Call to `log` is ambiguous as `2` versions of `log` are available: `log(i: String): void` and `log(i: Float): void` */ +/* @@? 18:6 Error TypeError: Call to `log` is ambiguous as `2` versions of `log` are available: `log(i: String): void` and `log(i: Double): void` */ +/* @@? 18:6 Error TypeError: Cannot use type 'void' as value. */ +/* @@? 18:18 Error TypeError: Variable 'barArg' is accessed before it's initialization. */ \ No newline at end of file -- Gitee