diff --git a/compiler/base/condition.cpp b/compiler/base/condition.cpp index be2ff503df95302e7761c3584a40fb4d0735b689..8a452c0570cbb3c2b3a393c45722ee3f67104511 100644 --- a/compiler/base/condition.cpp +++ b/compiler/base/condition.cpp @@ -120,7 +120,7 @@ void Condition::Compile(ETSGen *etsg, const ir::Expression *expr, Label *false_l VReg lhs = etsg->AllocReg(); bin_expr->Left()->Compile(etsg); - etsg->ApplyConversionAndStoreAccumulator(bin_expr, lhs, bin_expr->OperationType()); + etsg->ApplyConversionAndStoreAccumulator(bin_expr->Left(), lhs, bin_expr->OperationType()); bin_expr->Right()->Compile(etsg); etsg->ApplyConversion(bin_expr->Right(), bin_expr->OperationType()); etsg->Condition(bin_expr, bin_expr->OperatorType(), lhs, false_label); diff --git a/test/runtime/ets/if-unbox.ets b/test/runtime/ets/if-unbox.ets new file mode 100644 index 0000000000000000000000000000000000000000..5ce73ce0337a52561e7c0d4117e6564464b67d72 --- /dev/null +++ b/test/runtime/ets/if-unbox.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 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 cond1(): int { + let a = 1 as Int; + if(a != 5) return 1; + return 0; +} + +function cond2(): int { + if((1 as Int) != 5) return 1; + return 0; +} + +function main(): void { + assert cond1() == 1; + assert cond2() == 1; +}