diff --git a/ets2panda/checker/ets/arithmetic.cpp b/ets2panda/checker/ets/arithmetic.cpp index b76c779b5ae596684a2d710a8dac3be1938a5747..d0f6a2944c355f6d4d2ca1cf792ebbd38eff2d99 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 0000000000000000000000000000000000000000..f647326ec1e9999d55d3911093cb6e0d27c01c94 --- /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