From 980641c198cb449c9b5bc7aad627f32592c57cee Mon Sep 17 00:00:00 2001 From: turgutbababalim Date: Wed, 25 Jun 2025 09:39:53 +0300 Subject: [PATCH] Added generate flag Issue: ICHPE9 Description: Added a generate flag to tilde operators checking for better lowering. Signed-off-by: turgutbababalim --- ets2panda/checker/ETSAnalyzerHelpers.cpp | 3 +++ .../ast/compiler/ets/tilde_op_with_enum.ets | 23 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 ets2panda/test/ast/compiler/ets/tilde_op_with_enum.ets diff --git a/ets2panda/checker/ETSAnalyzerHelpers.cpp b/ets2panda/checker/ETSAnalyzerHelpers.cpp index 7bf8a4136f..4481f89fb3 100644 --- a/ets2panda/checker/ETSAnalyzerHelpers.cpp +++ b/ets2panda/checker/ETSAnalyzerHelpers.cpp @@ -533,6 +533,9 @@ void SetTsTypeForUnaryExpression(ETSChecker *checker, ir::UnaryExpression *expr, break; } case lexer::TokenType::PUNCTUATOR_TILDE: { + if (expr->Argument()->TsType()->IsETSEnumType()) { + expr->Argument()->AddAstNodeFlags(ir::AstNodeFlags::GENERATE_VALUE_OF); + } if (operandType == nullptr || !operandType->IsETSObjectType() || !operandType->AsETSObjectType()->HasObjectFlag(checker::ETSObjectFlags::CONVERTIBLE_TO_NUMERIC)) { expr->SetTsType(checker->GlobalTypeError()); diff --git a/ets2panda/test/ast/compiler/ets/tilde_op_with_enum.ets b/ets2panda/test/ast/compiler/ets/tilde_op_with_enum.ets new file mode 100644 index 0000000000..076d04cdbd --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/tilde_op_with_enum.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024-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. + */ + +const hex0001: int = 0x0001; + +enum FlagContacts { + ISLANDFLAG = hex0001, +} +let flags: int = 0; + +flags = ~FlagContacts.ISLANDFLAG; -- Gitee