From 28b3c4a77719451fa4fad683b35a67a7f4462be5 Mon Sep 17 00:00:00 2001 From: yanpeng51 Date: Fri, 25 Jul 2025 14:37:59 +0800 Subject: [PATCH] "Fix compilation test failure" Issue:https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICOSZ1 Signed-off-by: yanpeng51 --- ets2panda/checker/ets/object.cpp | 7 ++++++ .../constant_expression_test.ets | 23 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 ets2panda/test/ast/compiler/ets/constant_expression_test/constant_expression_test.ets diff --git a/ets2panda/checker/ets/object.cpp b/ets2panda/checker/ets/object.cpp index 63b773041d..b61b73fcec 100644 --- a/ets2panda/checker/ets/object.cpp +++ b/ets2panda/checker/ets/object.cpp @@ -1730,6 +1730,13 @@ bool ETSChecker::ValidateTupleIndex(const ETSTupleType *const tuple, ir::MemberE return false; } + if (expr->Property()->IsAssignmentExpression()) { + if (reportError) { + LogError(diagnostic::TUPLE_INDEX_NONCONST, {}, expr->Property()->Start()); + } + return false; + } + auto exprValue = GetTupleElementAccessValue(expr->Property()); if (!exprValue.has_value() || (*exprValue >= tuple->GetTupleSize())) { if (reportError) { diff --git a/ets2panda/test/ast/compiler/ets/constant_expression_test/constant_expression_test.ets b/ets2panda/test/ast/compiler/ets/constant_expression_test/constant_expression_test.ets new file mode 100644 index 0000000000..8a8a7fa511 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/constant_expression_test/constant_expression_test.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. + */ + +function main(): int { + let tuple: [number, number] = [0,5]; + tuple[/* @@ label */MathPartialSums.g_flag = 0] = 12; + return 0; +} + +/* @@@ label Error TypeError: Unresolved reference MathPartialSums */ +/* @@@ label Error TypeError: Only constant expression allowed for element access on tuples. */ -- Gitee