xxxxxxxxxx
auto readonly(T)(const(T)[] x) { return x; }
void main()
{
auto arr1 = [1, 2, 3];
auto arr2 = [1, 2, 3].readonly;
const arr3 = [1, 2, 3];
enum arr4 = [1, 2, 3];
static immutable arr5 = [1, 2, 3];
scope arr6 = [1, 2, 3];
pragma (msg, typeof(arr1)); // int[]
pragma (msg, typeof(arr2)); // const(int)[]
pragma (msg, typeof(arr3)); // const(int[])
pragma (msg, typeof(arr4)); // int[]
pragma (msg, typeof(arr5)); // int[]
pragma (msg, typeof(arr6)); // int[]
pragma (msg, "-----");
int[3] arr7 = [1, 2, 3];
const(int)[3] arr8 = [1, 2, 3].readonly;
const int[3] arr9 = [1, 2, 3];
enum int[3] arr10 = [1, 2, 3];
static immutable int[3] arr11 = [1, 2, 3];
scope int[3] arr12 = [1, 2, 3];
pragma (msg, typeof(arr7)); // int[3]
pragma (msg, typeof(arr8)); // const(int[3])
pragma (msg, typeof(arr9)); // const(int[3])
pragma (msg, typeof(arr10)); // int[3]
pragma (msg, typeof(arr11)); // immutable(int[3])
pragma (msg, typeof(arr12)); // int[3]
static assert(is(const(int)[3] == const(int[3])));
arr7 = arr1;
// arr8 = arr1; // Error: slice arr8[] is not mutable
// arr9 = arr1; // Error: slice arr9[] is not mutable
// arr10 = arr1; // Error: arr10 is not an lvalue and cannot be modified
// arr11 = arr1; // Error: slice arr11[] is not mutable
arr12 = arr1;
arr1 ~= 4;
// arr7 = arr1; // Array lengths don't match for copy: 4 != 3
// arr8 = arr1; // Error: slice arr8[] is not mutable
// arr9 = arr1; // Error: slice arr9[] is not mutable
// arr10 = arr1; // Error: arr10 is not an lvalue and cannot be modified
// arr11 = arr1; // Error: slice arr11[] is not mutable
// arr12 = arr1; // Array lengths don't match for copy: 4 != 3
}