1/* 2 * Copyright (c) 2024 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 x[1] = 0 18 y[0] = 10 19 y[1] = 'a' 20} 21 22function foo2(x : Readonly<int[]>, y : Readonly<[int, string]>) { 23 x[1] = 0 24 y[0] = 10 25 y[1] = 'a' 26} 27 28let x1 : readonly int[] = [1, 2] 29let y1 : readonly [int, string] = [1, "a"] 30x1[0] = 2 31y1[0] = 1 32 33let x2 : Readonly<int[]> = [0] 34x2[0] = 1 35let y2 : Readonly<[int, string]> 36y2[1] = "b" 37 38/* @@? 30:1 Error TypeError: Cannot modify an array or tuple content that has the readonly parameter */ 39/* @@? 31:1 Error TypeError: Cannot modify an array or tuple content that has the readonly parameter */ 40/* @@? 34:1 Error TypeError: Cannot modify an array or tuple content that has the readonly parameter */ 41/* @@? 36:1 Error TypeError: Cannot modify an array or tuple content that has the readonly parameter */ 42/* @@? 17:5 Error TypeError: Cannot modify an array or tuple content that has the readonly parameter */ 43/* @@? 18:5 Error TypeError: Cannot modify an array or tuple content that has the readonly parameter */ 44/* @@? 19:5 Error TypeError: Cannot modify an array or tuple content that has the readonly parameter */ 45/* @@? 23:5 Error TypeError: Cannot modify an array or tuple content that has the readonly parameter */ 46/* @@? 24:5 Error TypeError: Cannot modify an array or tuple content that has the readonly parameter */ 47/* @@? 25:5 Error TypeError: Cannot modify an array or tuple content that has the readonly parameter */ 48