diff --git a/ets2panda/checker/ets/object.cpp b/ets2panda/checker/ets/object.cpp index 63b773041d3e79286d070beb32f93153d5344656..b61b73fcec26c3b1677c9c48c29817761b42e9a4 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 0000000000000000000000000000000000000000..8a8a7fa5113cdb10df07fcb38928d96cfd8d1a19 --- /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. */