OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | |
2 // for details. All rights reserved. Use of this source code is governed by a | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 // Dart test program for testing params. | |
5 | |
6 // Convenience values. | |
7 var c = new C(); | |
8 var x = 42; | |
9 var y = 42; | |
10 var z = 42; | |
11 | |
12 // Trailing comma in parameter litss. | |
floitsch
2016/06/24 18:16:21
lists
| |
13 | |
14 // Typedefs. | |
15 typedef fx(x, ); /// none: ok | |
16 typedef fy([y,]); /// none: continued | |
17 typedef fxy(x, [y, ]); /// none: continued | |
18 typedef fz({z,}); /// none: continued | |
19 typedef fxz(x, {z, }); /// none: continued | |
20 | |
21 // As arguments type. | |
22 argfx(void f(x, )) {} /// none: continued | |
23 argfy(void f([y, ])) {} /// none: continued | |
24 argfxy(void f(x, [y, ])) {} /// none: continued | |
25 argfz(void f({z, })) {} /// none: continued | |
26 argfxz(void f(x, {z, })) {} /// none: continued | |
27 | |
28 // Top level functions | |
29 void topx(x,) {} /// none: continued | |
30 void topy([y, ]) {} /// none: continued | |
31 void topxy(x, [y, ]) {} /// none: continued | |
32 void topz({z, }) {} /// none: continued | |
33 void topxz(x, {z, }) {} /// none: continued | |
34 | |
35 void set topsetx(x, ) {} /// none: continued | |
36 | |
37 // After specific parameter formats. | |
38 void afterDefaultValueY([int y = 42, ]) {} /// none: continued | |
39 void afterDefaultValueZ({int z : 42, }) {} /// none: continued | |
40 void afterFunsigX(void f(),) {} /// none: continued | |
41 void afterFunsigY([void f(),]) {} /// none: continued | |
42 void afterFunsigZ({void f(),}) {} /// none: continued | |
43 void afterFunsigDefaultValueY([void f() = topy,]) {} /// none: continued | |
44 void afterFunsigDefaultValueZ({void f() : topt,}) {} /// none: continued | |
45 | |
46 class C { | |
47 C(); | |
48 | |
49 // Constructors. | |
50 C.x(x, ); /// none: continued | |
51 C.y([y, ]); /// none: continued | |
52 C.xy(x, [y, ]); /// none: continued | |
53 C.z({z, }); /// none: continued | |
54 C.xz(x, {z, }); /// none: continued | |
55 | |
56 // Static members | |
57 static void staticx(x,) {} /// none: continued | |
58 static void staticy([y, ]) {} /// none: continued | |
59 static void staticxy(x, [y, ]) {} /// none: continued | |
60 static void staticz({z, }) {} /// none: continued | |
61 static void staticxz(x, {z, }) {} /// none: continued | |
62 | |
63 static void set staticsetx(x, ) {} /// none: continued | |
64 | |
65 // Instance members | |
66 void instancex(x,) {} /// none: continued | |
67 void instancey([y, ]) {} /// none: continued | |
68 void instancexy(x, [y, ]) {} /// none: continued | |
69 void instancez({z, }) {} /// none: continued | |
70 void instancexz(x, {z, }) {} /// none: continued | |
71 | |
72 void set instancesetx(x, ) {} /// none: continued | |
73 | |
74 operator +(x, ) => this; /// none: continued | |
75 operator []=(x, y, ) {} /// none: continued | |
76 } | |
77 | |
78 main(args, ) { | |
79 testCalls(); /// none: continued | |
80 // Make sure the Bad class is checked. | |
81 new Bad().method(); | |
82 } | |
83 | |
84 void testCalls() { | |
85 // Check that all functions can be called normally | |
86 topx(x); /// none: continued | |
87 topy(y); /// none: continued | |
88 topxy(x, y); /// none: continued | |
89 topz(); /// none: continued | |
90 topz(z: z); /// none: continued | |
91 topxz(x); /// none: continued | |
92 topxz(x, z: z); /// none: continued | |
93 topsetx = x; /// none: continued | |
94 afterDefaultValueY(); /// none: continued | |
95 afterDefaultValueY(y); /// none: continued | |
96 afterDefaultValueZ(); /// none: continued | |
97 afterDefaultValueZ(z: z); /// none: continued | |
98 new C.x(x); /// none: continued | |
99 new C.xy(x); /// none: continued | |
100 new C.xy(x, y); /// none: continued | |
101 new C.y(y); /// none: continued | |
102 new C.xz(x); /// none: continued | |
103 new C.xz(x, z: z); /// none: continued | |
104 new C.z(z: z); /// none: continued | |
105 C.staticx(x); /// none: continued | |
106 C.staticy(y); /// none: continued | |
107 C.staticxy(x); /// none: continued | |
108 C.staticxy(x, y); /// none: continued | |
109 C.staticz(); /// none: continued | |
110 C.staticz(z: z); /// none: continued | |
111 C.staticxz(x); /// none: continued | |
112 C.staticxz(x, z: z); /// none: continued | |
113 C.staticsetx = x; /// none: continued | |
114 c.instancex(x); /// none: continued | |
115 c.instancey(); /// none: continued | |
116 c.instancey(y); /// none: continued | |
117 c.instancexy(x); /// none: continued | |
118 c.instancexy(x, y); /// none: continued | |
119 c.instancez(); /// none: continued | |
120 c.instancez(z: z); /// none: continued | |
121 c.instancexz(x); /// none: continued | |
122 c.instancexz(x, z: z); /// none: continued | |
123 c.instancesetx = x; /// none: continued | |
124 c + x; /// none: continued | |
125 c[x] = y; /// none: continued | |
126 | |
127 // Call with ekstra comma (not possible for setters and operators). | |
floitsch
2016/06/24 18:16:21
I still think this should be fixed :)
| |
128 topx(x, ); /// none: continued | |
129 topy(y, ); /// none: continued | |
130 topxy(x, y, ); /// none: continued | |
131 topxy(x, ); /// none: continued | |
132 topz(z: z, ); /// none: continued | |
133 topxz(x, ); /// none: continued | |
134 topxz(x, z: z, ); /// none: continued | |
135 new C.x(x, ); /// none: continued | |
136 new C.xy(x, y, ); /// none: continued | |
137 new C.xy(x, ); /// none: continued | |
138 new C.y(y, ); /// none: continued | |
139 new C.xz(x, ); /// none: continued | |
140 new C.xz(x, z: z, ); /// none: continued | |
141 new C.z(z: z, ); /// none: continued | |
142 C.staticx(x, ); /// none: continued | |
143 C.staticy(y, ); /// none: continued | |
144 C.staticxy(x, y, ); /// none: continued | |
145 C.staticxy(x, ); /// none: continued | |
146 C.staticz(z: z, ); /// none: continued | |
147 C.staticxz(x, ); /// none: continued | |
148 C.staticxz(x, z: z, ); /// none: continued | |
149 c.instancex(x, ); /// none: continued | |
150 c.instancey(y, ); /// none: continued | |
151 c.instancexy(x, y, ); /// none: continued | |
152 c.instancexy(x, ); /// none: continued | |
153 c.instancez(z: z, ); /// none: continued | |
154 c.instancexz(x, ); /// none: continued | |
155 c.instancexz(x, z: z, ); /// none: continued | |
156 | |
157 // Typedefs work as expected. | |
158 if (topx is! fx) throw "Bad type: $fx"; /// none: continued | |
159 if (topy is! fy) throw "Bad type: $fy"; /// none: continued | |
160 if (topxy is! fxy) throw "Bad type: $fxy"; /// none: continued | |
161 if (topz is! fz) throw "Bad type: $fz"; /// none: continued | |
162 if (topxz is! fxz) throw "Bad type: $fxz"; /// none: continued | |
163 | |
164 // Parameter types work (checked mode only test). | |
165 argfx(topx); /// none: continued | |
166 argfy(topy); /// none: continued | |
167 argfxy(topxy); /// none: continued | |
168 argfz(topz); /// none: continued | |
169 argfxz(topxz); /// none: continued | |
170 } | |
171 | |
172 | |
173 // Invalid syntax. This was invalid syntax before the addition of trailing | |
174 // commas too, and should stay that way. | |
175 void topBadEmpty(,) {} /// 1: compile-time error | |
176 void topBadStart(, a) {} /// 2: compile-time error | |
177 void topBadEnd(a,,) {} /// 3: compile-time error | |
178 void topBadMiddle(a,, b) {} /// 4: compile-time error | |
179 void topBadPosEmpty([]) {} /// 5: compile-time error | |
180 void topBadPosEmpty(,[]) {} /// 6: compile-time error | |
181 void topBadPosEmpty([,]) {} /// 7: compile-time error | |
182 void topBadPosEmpty([],) {} /// 8: compile-time error | |
183 void topBadPosStart(,[a]) {} /// 9: compile-time error | |
184 void topBadPosStart([, a]) {} /// 10: compile-time error | |
185 void topBadPosEnd([a,,]) {} /// 11: compile-time error | |
186 void topBadPosStart([a],) {} /// 12: compile-time error | |
187 void topBadPosMiddle([a,, b]) {} /// 13: compile-time error | |
188 void topBadNamEmpty({}) {} /// 14: compile-time error | |
189 void topBadNamEmpty(,{}) {} /// 15: compile-time error | |
190 void topBadNamEmpty({,}) {} /// 16: compile-time error | |
191 void topBadNamEmpty({},) {} /// 17: compile-time error | |
192 void topBadNamStart(,{a}) {} /// 18: compile-time error | |
193 void topBadNamStart({, a}) {} /// 19: compile-time error | |
194 void topBadNamEnd({a,,}) {} /// 20: compile-time error | |
195 void topBadNamStart({a},) {} /// 21: compile-time error | |
196 void topBadNamMiddle({a,, b}) {} /// 22: compile-time error | |
197 void set topSetBadEmpty(,) {} /// 23: compile-time error | |
198 void set topSetBadStart(, a) {} /// 24: compile-time error | |
199 void set topSetBadEnd(a,,) {} /// 25: compile-time error | |
200 void set topSetBadMiddle(a,, b) {} /// 26: compile-time error | |
201 class Bad { | |
202 Bad.empty(,) {} /// 27: compile-time error | |
203 Bad.start(, a) {} /// 28: compile-time error | |
204 Bad.end(a,,) {} /// 29: compile-time error | |
205 Bad.middle(a,, b) {} /// 30: compile-time error | |
206 Bad.posEmpty([]) {} /// 31: compile-time error | |
207 Bad.posEmpty(,[]) {} /// 32: compile-time error | |
208 Bad.posEmpty([,]) {} /// 33: compile-time error | |
209 Bad.posEmpty([],) {} /// 34: compile-time error | |
210 Bad.posStart(,[a]) {} /// 35: compile-time error | |
211 Bad.posStart([, a]) {} /// 36: compile-time error | |
212 Bad.posEnd([a,,]) {} /// 37: compile-time error | |
213 Bad.posStart([a],) {} /// 38: compile-time error | |
214 Bad.PosMiddle([a,, b]) {} /// 39: compile-time error | |
215 Bad.namEmpty({}) {} /// 40: compile-time error | |
216 Bad.namEmpty(,{}) {} /// 41: compile-time error | |
217 Bad.namEmpty({,}) {} /// 42: compile-time error | |
218 Bad.namEmpty({},) {} /// 43: compile-time error | |
219 Bad.namStart(,{a}) {} /// 44: compile-time error | |
220 Bad.namStart({, a}) {} /// 45: compile-time error | |
221 Bad.namEnd({a,,}) {} /// 46: compile-time error | |
222 Bad.namStart({a},) {} /// 47: compile-time error | |
223 Bad.namMiddle({a,, b}) {} /// 48: compile-time error | |
224 static void staticBadEmpty(,) {} /// 49: compile-time error | |
225 static void staticBadStart(, a) {} /// 50: compile-time error | |
226 static void staticBadEnd(a,,) {} /// 51: compile-time error | |
227 static void staticBadMiddle(a,, b) {} /// 52: compile-time error | |
228 static void staticBadPosEmpty([]) {} /// 53: compile-time error | |
229 static void staticBadPosEmpty(,[]) {} /// 54: compile-time error | |
230 static void staticBadPosEmpty([,]) {} /// 55: compile-time error | |
231 static void staticBadPosEmpty([],) {} /// 56: compile-time error | |
232 static void staticBadPosStart(,[a]) {} /// 57: compile-time error | |
233 static void staticBadPosStart([, a]) {} /// 58: compile-time error | |
234 static void staticBadPosEnd([a,,]) {} /// 59: compile-time error | |
235 static void staticBadPosStart([a],) {} /// 60: compile-time error | |
236 static void staticBadPosMiddle([a,, b]) {} /// 61: compile-time error | |
237 static void staticBadNamEmpty({}) {} /// 62: compile-time error | |
238 static void staticBadNamEmpty(,{}) {} /// 63: compile-time error | |
239 static void staticBadNamEmpty({,}) {} /// 64: compile-time error | |
240 static void staticBadNamEmpty({},) {} /// 65: compile-time error | |
241 static void staticBadNamStart(,{a}) {} /// 66: compile-time error | |
242 static void staticBadNamStart({, a}) {} /// 67: compile-time error | |
243 static void staticBadNamEnd({a,,}) {} /// 68: compile-time error | |
244 static void staticBadNamStart({a},) {} /// 69: compile-time error | |
245 static void staticBadNamMiddle({a,, b}) {} /// 70: compile-time error | |
246 static void set staticSetBadEmpty(,) {} /// 71: compile-time error | |
247 static void set staticSetBadStart(, a) {} /// 72: compile-time error | |
248 static void set staticSetBadEnd(a,,) {} /// 73: compile-time error | |
249 static void set staticSetBadMiddle(a,, b) {} /// 74: compile-time error | |
250 void instanceBadEmpty(,) {} /// 75: compile-time error | |
251 void instanceBadStart(, a) {} /// 76: compile-time error | |
252 void instanceBadEnd(a,,) {} /// 77: compile-time error | |
253 void instanceBadMiddle(a,, b) {} /// 78: compile-time error | |
254 void instanceBadPosEmpty([]) {} /// 79: compile-time error | |
255 void instanceBadPosEmpty(,[]) {} /// 80: compile-time error | |
256 void instanceBadPosEmpty([,]) {} /// 81: compile-time error | |
257 void instanceBadPosEmpty([],) {} /// 82: compile-time error | |
258 void instanceBadPosStart(,[a]) {} /// 83: compile-time error | |
259 void instanceBadPosStart([, a]) {} /// 84: compile-time error | |
260 void instanceBadPosEnd([a,,]) {} /// 85: compile-time error | |
261 void instanceBadPosStart([a],) {} /// 86: compile-time error | |
262 void instanceBadPosMiddle([a,, b]) {} /// 87: compile-time error | |
263 void instanceBadNamEmpty({}) {} /// 88: compile-time error | |
264 void instanceBadNamEmpty(,{}) {} /// 89: compile-time error | |
265 void instanceBadNamEmpty({,}) {} /// 90: compile-time error | |
266 void instanceBadNamEmpty({},) {} /// 91: compile-time error | |
267 void instanceBadNamStart(,{a}) {} /// 92: compile-time error | |
268 void instanceBadNamStart({, a}) {} /// 93: compile-time error | |
269 void instanceBadNamEnd({a,,}) {} /// 94: compile-time error | |
270 void instanceBadNamStart({a},) {} /// 95: compile-time error | |
271 void instanceBadNamMiddle({a,, b}) {} /// 96: compile-time error | |
272 void set instanceSetBadEmpty(,) {} /// 97: compile-time error | |
273 void set instanceSetBadStart(, a) {} /// 98: compile-time error | |
274 void set instanceSetBadEnd(a,,) {} /// 99: compile-time error | |
275 void set instanceSetBadMiddle(a,, b) {} /// 100: compile-time error | |
276 void operator *(,); /// 101: compile-time error | |
277 void operator *(, a); /// 102: compile-time error | |
278 void operator *(a,,); /// 103: compile-time error | |
279 void operator []=(, a); /// 104: compile-time error | |
280 void operator []=(a,,); /// 105: compile-time error | |
281 void operator []=(a,, b); /// 106: compile-time error | |
282 void operator []=(a,); /// 107: compile-time error | |
283 | |
284 method() { | |
285 // Local methods. | |
286 void localBadEmpty(,) {} /// 108: compile-time error | |
287 void localBadStart(, a) {} /// 109: compile-time error | |
288 void localBadEnd(a,,) {} /// 110: compile-time error | |
289 void localBadMiddle(a,, b) {} /// 111: compile-time error | |
290 void localBadPosEmpty([]) {} /// 112: compile-time error | |
291 void localBadPosEmpty(,[]) {} /// 113: compile-time error | |
292 void localBadPosEmpty([,]) {} /// 114: compile-time error | |
293 void localBadPosEmpty([],) {} /// 115: compile-time error | |
294 void localBadPosStart(,[a]) {} /// 116: compile-time error | |
295 void localBadPosStart([, a]) {} /// 117: compile-time error | |
296 void localBadPosEnd([a,,]) {} /// 118: compile-time error | |
297 void localBadPosStart([a],) {} /// 119: compile-time error | |
298 void localBadPosMiddle([a,, b]) {} /// 120: compile-time error | |
299 void localBadNamEmpty({}) {} /// 121: compile-time error | |
300 void localBadNamEmpty(,{}) {} /// 122: compile-time error | |
301 void localBadNamEmpty({,}) {} /// 123: compile-time error | |
302 void localBadNamEmpty({},) {} /// 124: compile-time error | |
303 void localBadNamStart(,{a}) {} /// 125: compile-time error | |
304 void localBadNamStart({, a}) {} /// 126: compile-time error | |
305 void localBadNamEnd({a,,}) {} /// 127: compile-time error | |
306 void localBadNamStart({a},) {} /// 128: compile-time error | |
307 void localBadNamMiddle({a,, b}) {} /// 129: compile-time error | |
308 | |
309 // invalid calls. | |
310 | |
311 topx(,); /// 130: compile-time error | |
312 topy(,); /// 131: compile-time error | |
313 topz(,); /// 132: compile-time error | |
314 topx(, x); /// 133: compile-time error | |
315 topz(, z:z); /// 134: compile-time error | |
316 topxy(x,, y); /// 135: compile-time error | |
317 topxz(x,, z:z); /// 136: compile-time error | |
318 topx(x,,); /// 137: compile-time error | |
319 topz(z:z,,); /// 138: compile-time error | |
320 | |
321 new C.x(,); /// 139: compile-time error | |
322 new C.y(,); /// 140: compile-time error | |
323 new C.z(,); /// 141: compile-time error | |
324 new C.x(, x); /// 142: compile-time error | |
325 new C.z(, z:z); /// 143: compile-time error | |
326 new C.xy(x,, y); /// 144: compile-time error | |
327 new C.xz(x,, z:z); /// 145: compile-time error | |
328 new C.x(x,,); /// 146: compile-time error | |
329 new C.z(z:z,,); /// 147: compile-time error | |
330 | |
331 C.staticx(,); /// 148: compile-time error | |
332 C.staticy(,); /// 149: compile-time error | |
333 C.staticz(,); /// 150: compile-time error | |
334 C.staticx(, x); /// 151: compile-time error | |
335 C.staticz(, z:z); /// 152: compile-time error | |
336 C.staticxy(x,, y); /// 153: compile-time error | |
337 C.staticxz(x,, z:z); /// 154: compile-time error | |
338 C.staticx(x,,); /// 155: compile-time error | |
339 C.staticz(z:z,,); /// 156: compile-time error | |
340 | |
341 c.instancex(,); /// 157: compile-time error | |
342 c.instancey(,); /// 158: compile-time error | |
343 c.instancez(,); /// 159: compile-time error | |
344 c.instancex(, x); /// 160: compile-time error | |
345 c.instancez(, z:z); /// 161: compile-time error | |
346 c.instancexy(x,, y); /// 162: compile-time error | |
347 c.instancexz(x,, z:z); /// 163: compile-time error | |
348 c.instancex(x,,); /// 164: compile-time error | |
349 c.instancez(z:z,,); /// 165: compile-time error | |
350 | |
351 c[x,] = y; /// 166: compile-time error | |
352 } | |
353 | |
354 // As parameters: | |
355 void f(void topBadEmpty(,)) {} /// 167: compile-time error | |
356 void f(void topBadStart(, a)) {} /// 168: compile-time error | |
357 void f(void topBadEnd(a,,)) {} /// 169: compile-time error | |
358 void f(void topBadMiddle(a,, b)) {} /// 170: compile-time error | |
359 void f(void topBadPosEmpty([])) {} /// 171: compile-time error | |
360 void f(void topBadPosEmpty(,[])) {} /// 172: compile-time error | |
361 void f(void topBadPosEmpty([,])) {} /// 173: compile-time error | |
362 void f(void topBadPosEmpty([],)) {} /// 174: compile-time error | |
363 void f(void topBadPosStart(,[a])) {} /// 175: compile-time error | |
364 void f(void topBadPosStart([, a])) {} /// 176: compile-time error | |
365 void f(void topBadPosEnd([a,,])) {} /// 177: compile-time error | |
366 void f(void topBadPosStart([a],)) {} /// 178: compile-time error | |
367 void f(void topBadPosMiddle([a,, b])) {} /// 179: compile-time error | |
368 void f(void topBadNamEmpty({})) {} /// 180: compile-time error | |
369 void f(void topBadNamEmpty(,{})) {} /// 181: compile-time error | |
370 void f(void topBadNamEmpty({,})) {} /// 182: compile-time error | |
371 void f(void topBadNamEmpty({},)) {} /// 183: compile-time error | |
372 void f(void topBadNamStart(,{a})) {} /// 184: compile-time error | |
373 void f(void topBadNamStart({, a})) {} /// 185: compile-time error | |
374 void f(void topBadNamEnd({a,,})) {} /// 186: compile-time error | |
375 void f(void topBadNamStart({a},)) {} /// 187: compile-time error | |
376 void f(void topBadNamMiddle({a,, b})) {} /// 188: compile-time error | |
377 } | |
378 | |
379 // As typedefs | |
380 typedef void BadEmpty(,); /// 189: compile-time error | |
381 typedef void BadStart(, a); /// 190: compile-time error | |
382 typedef void BadEnd(a,,); /// 191: compile-time error | |
383 typedef void BadMiddle(a,, b); /// 192: compile-time error | |
384 typedef void BadPosEmpty([]); /// 193: compile-time error | |
385 typedef void BadPosEmpty(,[]); /// 194: compile-time error | |
386 typedef void BadPosEmpty([,]); /// 195: compile-time error | |
387 typedef void BadPosEmpty([],); /// 196: compile-time error | |
388 typedef void BadPosStart(,[a]); /// 197: compile-time error | |
389 typedef void BadPosStart([, a]); /// 198: compile-time error | |
390 typedef void BadPosEnd([a,,]); /// 199: compile-time error | |
391 typedef void BadPosStart([a],); /// 200: compile-time error | |
392 typedef void BadPosMiddle([a,, b]); /// 201: compile-time error | |
393 typedef void BadNamEmpty({}); /// 202: compile-time error | |
394 typedef void BadNamEmpty(,{}); /// 203: compile-time error | |
395 typedef void BadNamEmpty({,}); /// 204: compile-time error | |
396 typedef void BadNamEmpty({},); /// 205: compile-time error | |
397 typedef void BadNamStart(,{a}); /// 206: compile-time error | |
398 typedef void BadNamStart({, a}); /// 207: compile-time error | |
399 typedef void BadNamEnd({a,,}); /// 208: compile-time error | |
400 typedef void BadNamStart({a},); /// 209: compile-time error | |
401 typedef void BadNamMiddle({a,, b}); /// 210: compile-time error | |
OLD | NEW |