From ea1168146347981b43185e23cf145ab2bb9cdd4e Mon Sep 17 00:00:00 2001 From: renguangxuan Date: Tue, 2 Sep 2025 17:40:43 +0800 Subject: [PATCH] Fix const expression fold bug Issue: #ICW15Y Signed-off-by: renguangxuan --- ets2panda/checker/ets/function.cpp | 5 +++- ets2panda/scripts/arkui.properties | 2 +- .../runtime/ets/const_expression_fold.ets | 27 +++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 ets2panda/test/runtime/ets/const_expression_fold.ets diff --git a/ets2panda/checker/ets/function.cpp b/ets2panda/checker/ets/function.cpp index 7034998575..17c28ec89e 100644 --- a/ets2panda/checker/ets/function.cpp +++ b/ets2panda/checker/ets/function.cpp @@ -594,7 +594,10 @@ bool ETSChecker::ValidateSignatureRequiredParams(Signature *substitutedSig, LogError(diagnostic::SPREAD_ONTO_SINGLE_PARAM, {}, argument->Start()); } return false; - } else if (argument->IsNumberLiteral()) { + } else if (argument->IsNumberLiteral() && + // Type inference is not needed for NumberLiteral produced by constant substitution, + // unless the literal results from constant folding. + (argument->OriginalNode() == nullptr || argument->AsNumberLiteral()->IsFolded())) { InferTypeForNumberLiteral(this, argument->AsNumberLiteral(), paramType); } diff --git a/ets2panda/scripts/arkui.properties b/ets2panda/scripts/arkui.properties index d5acadafe7..25fbb121b2 100644 --- a/ets2panda/scripts/arkui.properties +++ b/ets2panda/scripts/arkui.properties @@ -1,3 +1,3 @@ ARKUI_DEV_REPO=https://gitee.com/rri_opensource/koala_projects.git -ARKUI_DEV_BRANCH=panda_rev_11-interop_0702 +ARKUI_DEV_BRANCH=panda_rev_11-to-byte ARKUI_DEST=koala-sig diff --git a/ets2panda/test/runtime/ets/const_expression_fold.ets b/ets2panda/test/runtime/ets/const_expression_fold.ets new file mode 100644 index 0000000000..42bf20e198 --- /dev/null +++ b/ets2panda/test/runtime/ets/const_expression_fold.ets @@ -0,0 +1,27 @@ +/* + * 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() { + const a : int = 1; + const b : long = 1; + const c : long = b as long; + const d : float = 1; + const e : number = 1; + arktest.assertEQ(Type.of(a) instanceof IntType, true); + arktest.assertEQ(Type.of(b) instanceof LongType, true); + arktest.assertEQ(Type.of(c) instanceof LongType, true); + arktest.assertEQ(Type.of(d) instanceof FloatType, true); + arktest.assertEQ(Type.of(e) instanceof DoubleType, true); +} -- Gitee