From 7efe0e8e733fe325e9eb198e05838b19cde77e57 Mon Sep 17 00:00:00 2001 From: oh-rgx Date: Sat, 19 Jul 2025 20:29:37 +0800 Subject: [PATCH] Fix boolean type bite wise Issue: #ICNFLI Signed-off-by: oh-rgx --- .../ets/constantExpressionLowering.cpp | 2 +- .../test/ast/compiler/ets/bit_wise_expr.ets | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 ets2panda/test/ast/compiler/ets/bit_wise_expr.ets diff --git a/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp b/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp index 1667cf0370..d990bf0c27 100644 --- a/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp +++ b/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp @@ -927,7 +927,7 @@ static ir::AstNode *HandleBitwiseLogicalExpression(const ir::BinaryExpression *e return HandleNumericBitwiseLogicalExpression(expr, context); } - if (!left->IsBooleanLiteral() && !right->IsBooleanLiteral()) { + if (!left->IsBooleanLiteral() || !right->IsBooleanLiteral()) { LogError(context, diagnostic::WRONG_OPERAND_TYPE_FOR_BINARY_EXPRESSION, {}, expr->Start()); return CreateErrorIdentifier(expr, context->allocator); } diff --git a/ets2panda/test/ast/compiler/ets/bit_wise_expr.ets b/ets2panda/test/ast/compiler/ets/bit_wise_expr.ets new file mode 100644 index 0000000000..69ec693282 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/bit_wise_expr.ets @@ -0,0 +1,23 @@ +/* + * 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. + */ + +let tup : [['arkTs' | boolean, 1 | true]] = [['arkTs', 1]]; + +/* @@? 16:32 Error SyntaxError: Invalid Type. */ +/* @@? 16:32 Error SyntaxError: Unexpected token, expected ',' or ']'. */ +/* @@? 16:32 Error SyntaxError: Unexpected token '1'. */ +/* @@? 16:32 Error TypeError: Wrong type of operands for binary expression */ +/* @@? 16:40 Error SyntaxError: Unexpected token ']'. */ +/* @@? 16:41 Error SyntaxError: Unexpected token ']'. */ -- Gitee