1/* 2 * Copyright (c) 2024-2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16function foo1(x : readonly int[], y : readonly [int, string]) { 17 /* @@ label */x[1] = 0 18 /* @@ label1 */y[0] = 10 19 /* @@ label2 */y[1] = 'a' 20} 21 22function foo2(x : Readonly<int[]>, y : Readonly<[int, string]>) { 23 /* @@ label3 */x[1] = 0 24 /* @@ label4 */y[0] = 10 25 /* @@ label5 */y[1] = 'a' 26} 27 28let x1 : readonly int[] = [1, 2] 29let y1 : readonly [int, string] = [1, "a"] 30/* @@ label6 */x1[0] = 2 31/* @@ label7 */y1[0] = 1 32 33let x2 : Readonly<int[]> = [0] 34/* @@ label8 */x2[0] = 1 35let y2 : Readonly<[int, string]> 36/* @@ label9 */y2[1] = "b" 37 38/* @@@ label6 Error TypeError: Cannot modify an array or tuple content that has the readonly parameter */ 39/* @@@ label7 Error TypeError: Cannot modify an array or tuple content that has the readonly parameter */ 40/* @@@ label8 Error TypeError: Cannot modify an array or tuple content that has the readonly parameter */ 41/* @@@ label9 Error TypeError: Cannot modify an array or tuple content that has the readonly parameter */ 42/* @@@ label Error TypeError: Cannot modify an array or tuple content that has the readonly parameter */ 43/* @@@ label1 Error TypeError: Cannot modify an array or tuple content that has the readonly parameter */ 44/* @@@ label2 Error TypeError: Cannot modify an array or tuple content that has the readonly parameter */ 45/* @@@ label3 Error TypeError: Cannot modify an array or tuple content that has the readonly parameter */ 46/* @@@ label4 Error TypeError: Cannot modify an array or tuple content that has the readonly parameter */ 47/* @@@ label5 Error TypeError: Cannot modify an array or tuple content that has the readonly parameter */ 48