/
fail_arrayop2.d
370 lines (321 loc) · 14.2 KB
/
fail_arrayop2.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
// REQUIRED_ARGS: -o-
/*
TEST_OUTPUT:
---
fail_compilation/fail_arrayop2.d(13): Error: array operation `[1, 2, 3] - [1, 2, 3]` without destination memory not allowed
fail_compilation/fail_arrayop2.d(16): Error: invalid array operation `"a" - "b"` (possible missing [])
---
*/
void test2603() // Issue 2603 - ICE(cgcs.c) on subtracting string literals
{
auto c1 = [1,2,3] - [1,2,3];
// this variation is wrong code on D2, ICE ..\ztc\cgcs.c 358 on D1.
string c2 = "a" - "b";
}
/*
TEST_OUTPUT:
---
fail_compilation/fail_arrayop2.d(38): Error: array operation `-a[]` without destination memory not allowed (possible missing [])
fail_compilation/fail_arrayop2.d(39): Error: array operation `~a[]` without destination memory not allowed (possible missing [])
fail_compilation/fail_arrayop2.d(41): Error: array operation `a[] + a[]` without destination memory not allowed (possible missing [])
fail_compilation/fail_arrayop2.d(42): Error: array operation `a[] - a[]` without destination memory not allowed (possible missing [])
fail_compilation/fail_arrayop2.d(43): Error: array operation `a[] * a[]` without destination memory not allowed (possible missing [])
fail_compilation/fail_arrayop2.d(44): Error: array operation `a[] / a[]` without destination memory not allowed (possible missing [])
fail_compilation/fail_arrayop2.d(45): Error: array operation `a[] % a[]` without destination memory not allowed (possible missing [])
fail_compilation/fail_arrayop2.d(46): Error: array operation `a[] ^ a[]` without destination memory not allowed (possible missing [])
fail_compilation/fail_arrayop2.d(47): Error: array operation `a[] & a[]` without destination memory not allowed (possible missing [])
fail_compilation/fail_arrayop2.d(48): Error: array operation `a[] | a[]` without destination memory not allowed (possible missing [])
fail_compilation/fail_arrayop2.d(49): Error: array operation `a[] ^^ a[]` without destination memory not allowed (possible missing [])
---
*/
void test9459()
{
int[] a = [1, 2, 3];
a = -a[];
a = ~a[];
a = a[] + a[];
a = a[] - a[];
a = a[] * a[];
a = a[] / a[];
a = a[] % a[];
a = a[] ^ a[];
a = a[] & a[];
a = a[] | a[];
a = a[] ^^ a[];
}
/*
TEST_OUTPUT:
---
fail_compilation/fail_arrayop2.d(75): Error: array operation `a[] + a[]` without destination memory not allowed
fail_compilation/fail_arrayop2.d(76): Error: array operation `a[] - a[]` without destination memory not allowed
fail_compilation/fail_arrayop2.d(77): Error: array operation `a[] * a[]` without destination memory not allowed
fail_compilation/fail_arrayop2.d(78): Error: array operation `a[] / a[]` without destination memory not allowed
fail_compilation/fail_arrayop2.d(79): Error: array operation `a[] % a[]` without destination memory not allowed
fail_compilation/fail_arrayop2.d(80): Error: array operation `a[] ^ a[]` without destination memory not allowed
fail_compilation/fail_arrayop2.d(81): Error: array operation `a[] & a[]` without destination memory not allowed
fail_compilation/fail_arrayop2.d(82): Error: array operation `a[] | a[]` without destination memory not allowed
fail_compilation/fail_arrayop2.d(83): Error: array operation `a[] ^^ 10` without destination memory not allowed
fail_compilation/fail_arrayop2.d(84): Error: array operation `-a[]` without destination memory not allowed
fail_compilation/fail_arrayop2.d(85): Error: array operation `~a[]` without destination memory not allowed
fail_compilation/fail_arrayop2.d(90): Error: array operation `[1] + a[]` without destination memory not allowed
fail_compilation/fail_arrayop2.d(91): Error: array operation `[1] + a[]` without destination memory not allowed
---
*/
void test12179()
{
void foo(int[]) {}
int[1] a;
foo(a[] + a[]);
foo(a[] - a[]);
foo(a[] * a[]);
foo(a[] / a[]);
foo(a[] % a[]);
foo(a[] ^ a[]);
foo(a[] & a[]);
foo(a[] | a[]);
foo(a[] ^^ 10);
foo(-a[]);
foo(~a[]);
// from issue 11992
int[] arr1;
int[][] arr2;
arr1 ~= [1] + a[]; // NG
arr2 ~= [1] + a[]; // NG
}
/*
TEST_OUTPUT:
---
fail_compilation/fail_arrayop2.d(105): Error: array operation `h * y[]` without destination memory not allowed
---
*/
void test12381()
{
double[2] y;
double h;
double[2] temp1 = cast(double[2])(h * y[]);
}
/*
TEST_OUTPUT:
---
fail_compilation/fail_arrayop2.d(118): Error: array operation `-a[]` without destination memory not allowed
fail_compilation/fail_arrayop2.d(120): Error: array operation `(-a[])[0..4]` without destination memory not allowed
---
*/
float[] test12769(float[] a)
{
if (a.length < 4)
return -a[];
else
return (-a[])[0..4];
}
/*
TEST_OUTPUT:
---
fail_compilation/fail_arrayop2.d(137): Error: array operation `a[] - a[]` without destination memory not allowed
fail_compilation/fail_arrayop2.d(139): Error: array operation `a[] - a[]` without destination memory not allowed
fail_compilation/fail_arrayop2.d(140): Error: array operation `a[] - a[]` without destination memory not allowed
fail_compilation/fail_arrayop2.d(143): Error: array operation `a[] - a[]` without destination memory not allowed
fail_compilation/fail_arrayop2.d(145): Error: array operation `a[] - a[]` without destination memory not allowed
---
*/
void test13208()
{
int[] a;
auto arr = [a[] - a[]][0];
auto aa1 = [1 : a[] - a[]];
auto aa2 = [a[] - a[] : 1];
struct S { int[] a; }
auto s = S(a[] - a[]);
auto n = int(a[] - a[]);
}
/*
TEST_OUTPUT:
---
fail_compilation/fail_arrayop2.d(160): Error: array operation `a[] * a[]` without destination memory not allowed
fail_compilation/fail_arrayop2.d(161): Error: array operation `(a[] * a[])[0..1]` without destination memory not allowed
fail_compilation/fail_arrayop2.d(164): Error: array operation `a[] * a[]` without destination memory not allowed (possible missing [])
fail_compilation/fail_arrayop2.d(165): Error: array operation `(a[] * a[])[0..1]` without destination memory not allowed (possible missing [])
---
*/
void test13497()
{
int[1] a;
auto b1 = (a[] * a[])[];
auto b2 = (a[] * a[])[0..1];
int[] c;
c = (a[] * a[])[];
c = (a[] * a[])[0..1];
}
/*
TEST_OUTPUT:
---
fail_compilation/fail_arrayop2.d(181): Error: array operation `data[segmentId][28..29] & cast(ubyte)(1 << 0)` without destination memory not allowed
---
*/
void test13910()
{
ubyte[][] data;
size_t segmentId;
bool isGroup()
{
return !!((data[segmentId][28..29]) & (1 << 0));
}
}
/*
TEST_OUTPUT:
---
fail_compilation/fail_arrayop2.d(195): Error: array operation `a[] + 1` without destination memory not allowed
fail_compilation/fail_arrayop2.d(195): Error: array operation `a[] * 2` without destination memory not allowed
---
*/
void test14895()
{
int[] a;
int[] b = (a[] + 1) ~ a[] * 2;
}
/*
TEST_OUTPUT:
---
fail_compilation/fail_arrayop2.d(247): Error: array operation `[1] * 6` without destination memory not allowed
fail_compilation/fail_arrayop2.d(248): Error: array operation `[1] * 6` without destination memory not allowed
fail_compilation/fail_arrayop2.d(249): Error: array operation `[1] * 6` without destination memory not allowed
fail_compilation/fail_arrayop2.d(253): Error: array operation `[1] * 6` without destination memory not allowed
fail_compilation/fail_arrayop2.d(256): Error: array operation `[1] * 6` without destination memory not allowed
fail_compilation/fail_arrayop2.d(265): Error: array operation `[1] * 6` without destination memory not allowed
fail_compilation/fail_arrayop2.d(268): Error: array operation `[1] * 6` without destination memory not allowed
fail_compilation/fail_arrayop2.d(269): Error: array operation `"abc"[] + '\x01'` without destination memory not allowed
fail_compilation/fail_arrayop2.d(272): Error: array operation `[1] * 6` without destination memory not allowed
fail_compilation/fail_arrayop2.d(275): Error: `([1] * 6)[0..2]` is not an lvalue and cannot be modified
fail_compilation/fail_arrayop2.d(278): Error: can only `*` a pointer, not a `int[]`
fail_compilation/fail_arrayop2.d(281): Deprecation: The `delete` keyword has been deprecated. Use `object.destroy()` (and `core.memory.GC.free()` if applicable) instead.
fail_compilation/fail_arrayop2.d(281): Error: `[1] * 6` is not an lvalue and cannot be modified
fail_compilation/fail_arrayop2.d(284): Error: array operation `da[] * 6` without destination memory not allowed
fail_compilation/fail_arrayop2.d(287): Error: array operation `da[] * 6` without destination memory not allowed
fail_compilation/fail_arrayop2.d(290): Error: `[1] * 6` is not an lvalue and cannot be modified
fail_compilation/fail_arrayop2.d(291): Error: array operation `[1] * 6` without destination memory not allowed
fail_compilation/fail_arrayop2.d(294): Error: `[1] * 6` is not an lvalue and cannot be modified
fail_compilation/fail_arrayop2.d(295): Error: `([1] * 6)[]` is not an lvalue and cannot be modified
fail_compilation/fail_arrayop2.d(298): Error: array operation `[1] * 6` without destination memory not allowed
fail_compilation/fail_arrayop2.d(299): Error: array operation `[1] * 6` without destination memory not allowed
fail_compilation/fail_arrayop2.d(300): Error: array operation `[1] * 6` without destination memory not allowed
fail_compilation/fail_arrayop2.d(303): Error: `[1] * 6` is not an lvalue and cannot be modified
fail_compilation/fail_arrayop2.d(304): Error: `[1] * 6` is not an lvalue and cannot be modified
fail_compilation/fail_arrayop2.d(307): Error: `[1] * 6` is not of integral type, it is a `int[]`
fail_compilation/fail_arrayop2.d(308): Error: `[1] * 6` is not of integral type, it is a `int[]`
fail_compilation/fail_arrayop2.d(309): Error: `[1] * 6` is not of integral type, it is a `int[]`
fail_compilation/fail_arrayop2.d(312): Error: array operation `[1] * 6` without destination memory not allowed
fail_compilation/fail_arrayop2.d(313): Error: array operation `[1] * 6` without destination memory not allowed
fail_compilation/fail_arrayop2.d(316): Error: array operation `[1] * 6` without destination memory not allowed
fail_compilation/fail_arrayop2.d(317): Error: array operation `[1] * 6` without destination memory not allowed
fail_compilation/fail_arrayop2.d(318): Error: array operation `[1] * 6` without destination memory not allowed
fail_compilation/fail_arrayop2.d(321): Error: array operation `[1] * 6` without destination memory not allowed
fail_compilation/fail_arrayop2.d(321): Error: array operation `[1] * 6` without destination memory not allowed
fail_compilation/fail_arrayop2.d(321): Error: array operation `[1] * 6` without destination memory not allowed
---
*/
// Test all expressions, which can take arrays as their operands but cannot be a part of array operation.
void test15407exp()
{
struct S { int[] a; }
void f(int[] a) {}
int[] da;
int[6] sa;
{ auto r = [[1] * 6]; } // ArrayLiteralExp
{ auto r = [[1] * 6 :
[1] * 6]; } // AssocArrayLiteralExp
//TupleExp
// StructLiteralExp.elements <- preFunctionParameters in CallExp
{ auto r = S([1] * 6); }
// NewExp.newargs/arguments <- preFunctionParameters
{ auto r = new S([1] * 6); }
// TODO: TypeidExp
//auto ti = typeid([1] * 6);
//auto foo(T)(T t) {}
//foo(typeid([1] * 6));
//auto a = [typeid([1] * 6)];
// CommaExp.e1
{ auto r = ([1] * 6, 1); }
// AssertExp
assert([1] * 6,
cast(char)1 + "abc"[]);
// CallExp.arguments <- preFunctionParameters
f([1] * 6);
// AddrExp, if a CT-known length slice can become an TypeSarray lvalue in the future.
{ auto r = &(([1] * 6)[0..2]); }
// PtrExp, *([1] * 6).ptr is also invalid -> show better diagnostic
{ auto r = *([1] * 6); }
// DeleteExp - e1
delete ([1] * 6);
// TypeDArray.dotExp, cannot check in ArrayLengthExp.semantic()
{ auto r = (6 * da[]).length; }
// IndexExp - e1
{ auto x1 = (da[] * 6)[1]; }
// Pre, PostExp - e1
([1] * 6)++;
--([1] * 6);
// AssignExp e1
([1] * 6) = 10;
([1] * 6)[] = 10;
// BinAssignExp e1
([1] * 6) += 1;
([1] * 6)[] *= 2;
([1] * 6)[] ^^= 3;
// CatExp e1
([1] * 6) ~= 1;
([1] * 6)[] ~= 2;
// Shl, Shr, UshrExp - e1, e2 --> checkIntegralBin
{ auto r = ([1] * 6) << 1; }
{ auto r = ([1] * 6) >> 1; }
{ auto r = ([1] * 6) >>> 1; }
// AndAnd, OrOrExp - e1, e2
{ auto r = sa[0..5] && [1] * 6; }
{ auto r = sa[0..5] || [1] * 6; }
// Cmp, Equal, IdentityExp - e1, e2
{ auto r = sa[0..5] <= [1] * 6; }
{ auto r = sa[0..5] == [1] * 6; }
{ auto r = sa[0..5] is [1] * 6; }
// CondExp - econd, e1, e2
{ auto r = [1] * 6 ? [1] * 6 : [1] * 6; }
}
/*
TEST_OUTPUT:
---
fail_compilation/fail_arrayop2.d(342): Error: array operation `[1] * 6` without destination memory not allowed
fail_compilation/fail_arrayop2.d(345): Error: array operation `[1] * 6` without destination memory not allowed
fail_compilation/fail_arrayop2.d(348): Error: array operation `[1] * 6` without destination memory not allowed
fail_compilation/fail_arrayop2.d(349): Error: array operation `[1] * 6` without destination memory not allowed
fail_compilation/fail_arrayop2.d(350): Error: array operation `[1] * 6` without destination memory not allowed
fail_compilation/fail_arrayop2.d(353): Error: array operation `[1] * 6` without destination memory not allowed
fail_compilation/fail_arrayop2.d(356): Error: array operation `[1] * 6` without destination memory not allowed
fail_compilation/fail_arrayop2.d(359): Error: array operation `"str"[] + cast(immutable(char))1` without destination memory not allowed
fail_compilation/fail_arrayop2.d(367): Error: CTFE internal error: non-constant value `"uvt"[]`
---
*/
// Test all statements, which can take arrays as their operands.
void test15407stmt()
{
// ExpStatement - exp
[1] * 6;
// DoStatement - condition
do {} while ([1] * 6);
// ForStatement - condition, increment
for ([1] * 6; // init == ExpStatement
[1] * 6;
[1] * 6) {}
// ForeachStatement - aggr -> lowered to ForStatement
foreach (e; [1] * 6) {}
// IfStatement condition
if ([1] * 6) {}
// SwitchStatement - condition
switch ("str"[] + 1)
{
case "tus": break;
default: break;
}
// CaseStatement - exp
switch ("tus")
{
case "uvt"[] - 1: break;
default: break;
}
}