@@ -240,6 +240,267 @@ func outOfOrder(_ a : Int, b: Int) {
240
240
outOfOrder ( b: 42 , 52 ) // expected-error {{unnamed argument #2 must precede argument 'b'}} {{14-14=52, }} {{19-23=}}
241
241
}
242
242
243
+ // -------------------------------------------
244
+ // Positions around defaults and variadics
245
+ // -------------------------------------------
246
+
247
+ struct PositionsAroundDefaultsAndVariadics {
248
+ // unlabeled defaulted around labeled parameter
249
+ func f1( _ a: Bool = false , _ b: Int = 0 , c: String = " " , _ d: [ Int ] = [ ] ) { }
250
+
251
+ func test_f1( ) {
252
+ f1 ( true , 2 , c: " 3 " , [ 4 ] )
253
+
254
+ f1 ( true , c: " 3 " , 2 , [ 4 ] ) // expected-error {{unnamed argument #4 must precede argument 'c'}}
255
+
256
+ f1 ( true , c: " 3 " , [ 4 ] , 2 ) // expected-error {{unnamed argument #4 must precede argument 'c'}}
257
+
258
+ f1 ( true , c: " 3 " , 2 ) // expected-error {{cannot convert value of type 'Int' to expected argument type '[Int]'}}
259
+
260
+ f1 ( true , c: " 3 " , [ 4 ] )
261
+
262
+ f1 ( c: " 3 " , 2 , [ 4 ] ) // expected-error {{unnamed argument #3 must precede argument 'c'}}
263
+
264
+ f1 ( c: " 3 " , [ 4 ] , 2 ) // expected-error {{unnamed argument #3 must precede argument 'c'}}
265
+
266
+ f1 ( c: " 3 " , 2 ) // expected-error {{cannot convert value of type 'Int' to expected argument type '[Int]'}}
267
+
268
+ f1 ( c: " 3 " , [ 4 ] )
269
+
270
+ f1 ( b: " 2 " , [ 3 ] ) // expected-error {{unnamed argument #2 must precede argument 'b'}}
271
+
272
+ f1 ( b: " 2 " , 1 ) // expected-error {{unnamed argument #2 must precede argument 'b'}}
273
+
274
+ f1 ( b: " 2 " , [ 3 ] , 1 ) // expected-error {{unnamed argument #2 must precede argument 'b'}}
275
+
276
+ f1 ( b: " 2 " , 1 , [ 3 ] ) // expected-error {{unnamed argument #2 must precede argument 'b'}}
277
+ }
278
+
279
+ // unlabeled variadics before labeled parameter
280
+ func f2( _ a: Bool = false , _ b: Int ... , c: String = " " , _ d: [ Int ] = [ ] ) { }
281
+
282
+ func test_f2( ) {
283
+ f2 ( true , 21 , 22 , 23 , c: " 3 " , [ 4 ] )
284
+
285
+ f2 ( true , " 21 " , 22 , 23 , c: " 3 " , [ 4 ] ) // expected-error {{cannot convert value of type 'String' to expected argument type 'Int'}}
286
+
287
+ f2 ( true , 21 , " 22 " , 23 , c: " 3 " , [ 4 ] ) // expected-error {{cannot convert value of type 'String' to expected argument type 'Int'}}
288
+
289
+ f2 ( true , 21 , 22 , " 23 " , c: " 3 " , [ 4 ] ) // expected-error {{cannot convert value of type 'String' to expected argument type 'Int'}}
290
+
291
+ f2 ( true , 21 , 22 , c: " 3 " , [ 4 ] )
292
+ f2 ( true , 21 , c: " 3 " , [ 4 ] )
293
+ f2 ( true , c: " 3 " , [ 4 ] )
294
+
295
+ f2 ( true , c: " 3 " , 21 ) // expected-error {{cannot convert value of type 'Int' to expected argument type '[Int]'}}
296
+
297
+ f2 ( true , c: " 3 " , 21 , [ 4 ] ) // expected-error {{unnamed argument #4 must precede argument 'c'}}
298
+ // expected-error@-1 {{cannot pass array of type '[Int]' as variadic arguments of type 'Int'}}
299
+ // expected-note@-2 {{remove brackets to pass array elements directly}}
300
+
301
+ f2 ( true , c: " 3 " , [ 4 ] , 21 ) // expected-error {{unnamed argument #4 must precede argument 'c'}}
302
+
303
+ f2 ( true , [ 4 ] ) // expected-error {{cannot pass array of type '[Int]' as variadic arguments of type 'Int'}}
304
+ // expected-note@-1 {{remove brackets to pass array elements directly}}
305
+
306
+ f2 ( true , 21 , [ 4 ] ) // expected-error {{cannot pass array of type '[Int]' as variadic arguments of type 'Int'}}
307
+ // expected-note@-1 {{remove brackets to pass array elements directly}}
308
+
309
+ f2 ( true , 21 , 22 , [ 4 ] ) // expected-error {{cannot pass array of type '[Int]' as variadic arguments of type 'Int'}}
310
+ // expected-note@-1 {{remove brackets to pass array elements directly}}
311
+
312
+ f2 ( 21 , 22 , 23 , c: " 3 " , [ 4 ] ) // expected-error {{type 'Int' cannot be used as a boolean; test for '!= 0' instead}}
313
+
314
+ f2 ( 21 , 22 , c: " 3 " , [ 4 ] ) // expected-error {{type 'Int' cannot be used as a boolean; test for '!= 0' instead}}
315
+
316
+ f2 ( 21 , c: " 3 " , [ 4 ] ) // expected-error {{type 'Int' cannot be used as a boolean; test for '!= 0' instead}}
317
+
318
+ f2 ( c: " 3 " , [ 4 ] )
319
+ f2 ( c: " 3 " )
320
+ f2 ( )
321
+
322
+ f2 ( c: " 3 " , 21 ) // expected-error {{cannot convert value of type 'Int' to expected argument type '[Int]'}}
323
+
324
+ f2 ( c: " 3 " , 21 , [ 4 ] ) // expected-error {{incorrect argument labels in call (have 'c:_:_:', expected '_:_:c:_:')}}
325
+ // expected-error@-1 {{cannot convert value of type 'Int' to expected argument type '[Int]'}}
326
+ // expected-error@-2 {{cannot convert value of type '[Int]' to expected argument type 'Bool'}}
327
+
328
+ f2 ( c: " 3 " , [ 4 ] , 21 ) // expected-error {{incorrect argument labels in call (have 'c:_:_:', expected '_:_:c:_:')}}
329
+ // expected-error@-1 {{type 'Int' cannot be used as a boolean; test for '!= 0' instead}}
330
+
331
+ f2 ( [ 4 ] ) // expected-error {{cannot convert value of type '[Int]' to expected argument type 'Bool'}}
332
+
333
+ f2 ( 21 , [ 4 ] ) // expected-error {{type 'Int' cannot be used as a boolean; test for '!= 0' instead}}
334
+ // expected-error@-1 {{cannot pass array of type '[Int]' as variadic arguments of type 'Int'}}
335
+ // expected-note@-2 {{remove brackets to pass array elements directly}}
336
+
337
+ f2 ( 21 , 22 , [ 4 ] ) // expected-error {{type 'Int' cannot be used as a boolean; test for '!= 0' instead}}
338
+ // expected-error@-1 {{cannot pass array of type '[Int]' as variadic arguments of type 'Int'}}
339
+ // expected-note@-2 {{remove brackets to pass array elements directly}}
340
+ }
341
+
342
+ // labeled variadics before labeled parameter
343
+ func f3( _ a: Bool = false , b: Int ... , c: String = " " , _ d: [ Int ] = [ ] ) { }
344
+
345
+ func test_f3( ) {
346
+ f3 ( true , b: 21 , 22 , 23 , c: " 3 " , [ 4 ] )
347
+
348
+ f3 ( true , b: " 21 " , 22 , 23 , c: " 3 " , [ 4 ] ) // expected-error {{cannot convert value of type 'String' to expected argument type 'Int'}}
349
+
350
+ f3 ( true , b: 21 , " 22 " , 23 , c: " 3 " , [ 4 ] ) // expected-error {{cannot convert value of type 'String' to expected argument type 'Int'}}
351
+
352
+ f3 ( true , b: 21 , 22 , " 23 " , c: " 3 " , [ 4 ] ) // expected-error {{cannot convert value of type 'String' to expected argument type 'Int'}}
353
+
354
+ f3 ( true , b: 21 , 22 , c: " 3 " , [ 4 ] )
355
+ f3 ( true , b: 21 , c: " 3 " , [ 4 ] )
356
+ f3 ( true , c: " 3 " , [ 4 ] )
357
+
358
+ f3 ( true , c: " 3 " , b: 21 ) // expected-error {{argument 'b' must precede argument 'c'}}
359
+
360
+ f3 ( true , c: " 3 " , b: 21 , [ 4 ] ) // expected-error {{argument 'b' must precede argument 'c'}}
361
+ // expected-error@-1 {{cannot pass array of type '[Int]' as variadic arguments of type 'Int'}}
362
+ // expected-note@-2 {{remove brackets to pass array elements directly}}
363
+
364
+ f3 ( true , c: " 3 " , [ 4 ] , b: 21 ) // expected-error {{argument 'b' must precede argument 'c'}}
365
+
366
+ f3 ( true , b: 21 , [ 4 ] ) // expected-error {{cannot pass array of type '[Int]' as variadic arguments of type 'Int'}}
367
+ // expected-note@-1 {{remove brackets to pass array elements directly}}
368
+
369
+ f3 ( b: 21 , 22 , 23 , c: " 3 " , [ 4 ] )
370
+ f3 ( b: 21 , 22 , c: " 3 " , [ 4 ] )
371
+ f3 ( b: 21 , c: " 3 " , [ 4 ] )
372
+ f3 ( c: " 3 " , [ 4 ] )
373
+
374
+ f3 ( [ 4 ] ) // expected-error {{cannot convert value of type '[Int]' to expected argument type 'Bool'}}
375
+
376
+ f3 ( )
377
+
378
+ f3 ( c: " 3 " , b: 21 ) // expected-error {{incorrect argument labels in call (have 'c:b:', expected '_:b:c:_:')}}
379
+
380
+ f3 ( c: " 3 " , b: 21 , [ 4 ] ) // expected-error {{incorrect argument labels in call (have 'c:b:_:', expected '_:b:c:_:')}}
381
+ // expected-error@-1 {{cannot pass array of type '[Int]' as variadic arguments of type 'Int'}}
382
+ // expected-note@-2 {{remove brackets to pass array elements directly}}
383
+
384
+ f3 ( c: " 3 " , [ 4 ] , b: 21 ) // expected-error {{incorrect argument labels in call (have 'c:_:b:', expected '_:b:c:_:')}}
385
+ }
386
+
387
+ // unlabeled variadics after labeled parameter
388
+ func f4( _ a: Bool = false , b: String = " " , _ c: Int ... , d: [ Int ] = [ ] ) { }
389
+
390
+ func test_f4( ) {
391
+ f4 ( true , b: " 2 " , 31 , 32 , 33 , d: [ 4 ] )
392
+
393
+ f4 ( true , b: " 2 " , " 31 " , 32 , 33 , d: [ 4 ] ) // expected-error {{cannot convert value of type 'String' to expected argument type 'Int'}}
394
+
395
+ f4 ( true , b: " 2 " , 31 , " 32 " , 33 , d: [ 4 ] ) // expected-error {{cannot convert value of type 'String' to expected argument type 'Int'}}
396
+
397
+ f4 ( true , b: " 2 " , 31 , 32 , " 33 " , d: [ 4 ] ) // expected-error {{cannot convert value of type 'String' to expected argument type 'Int'}}
398
+
399
+ f4 ( true , b: " 2 " , 31 , 32 , d: [ 4 ] )
400
+ f4 ( true , b: " 2 " , 31 , d: [ 4 ] )
401
+ f4 ( true , b: " 2 " , d: [ 4 ] )
402
+
403
+ f4 ( true , 31 , b: " 2 " , d: [ 4 ] ) // expected-error {{argument 'b' must precede unnamed argument #2}}
404
+
405
+ f4 ( true , b: " 2 " , d: [ 4 ] , 31 ) // expected-error {{unnamed argument #4 must precede argument 'd'}}
406
+
407
+ f4 ( true , b: " 2 " , 31 )
408
+ f4 ( true , b: " 2 " )
409
+
410
+ f4 ( true )
411
+ f4 ( true , 31 )
412
+ f4 ( true , 31 , d: [ 4 ] )
413
+ f4 ( true , 31 , 32 )
414
+ f4 ( true , 31 , 32 , d: [ 4 ] )
415
+
416
+ f4 ( b: " 2 " , 31 , 32 , 33 , d: [ 4 ] )
417
+
418
+ f4 ( b: " 2 " , " 31 " , 32 , 33 , d: [ 4 ] ) // expected-error {{cannot convert value of type 'String' to expected argument type 'Int'}}
419
+
420
+ f4 ( b: " 2 " , 31 , " 32 " , 33 , d: [ 4 ] ) // expected-error {{cannot convert value of type 'String' to expected argument type 'Int'}}
421
+
422
+ f4 ( b: " 2 " , 31 , 32 , " 33 " , d: [ 4 ] ) // expected-error {{cannot convert value of type 'String' to expected argument type 'Int'}}
423
+
424
+ f4 ( b: " 2 " , 31 , 32 , d: [ 4 ] )
425
+ f4 ( b: " 2 " , 31 , d: [ 4 ] )
426
+ f4 ( b: " 2 " , d: [ 4 ] )
427
+
428
+ f4 ( 31 , b: " 2 " , d: [ 4 ] ) // expected-error {{type 'Int' cannot be used as a boolean; test for '!= 0' instead}}
429
+
430
+ f4 ( b: " 2 " , d: [ 4 ] , 31 ) // expected-error {{unnamed argument #3 must precede argument 'b'}}
431
+
432
+ f4 ( b: " 2 " , 31 )
433
+ f4 ( b: " 2 " , 31 , 32 )
434
+ f4 ( b: " 2 " )
435
+
436
+ f4 ( )
437
+
438
+ f4 ( 31 ) // expected-error {{type 'Int' cannot be used as a boolean; test for '!= 0' instead}}
439
+
440
+ f4 ( 31 , d: [ 4 ] ) // expected-error {{type 'Int' cannot be used as a boolean; test for '!= 0' instead}}
441
+
442
+ f4 ( 31 , 32 ) // expected-error {{type 'Int' cannot be used as a boolean; test for '!= 0' instead}}
443
+
444
+ f4 ( 31 , 32 , d: [ 4 ] ) // expected-error {{type 'Int' cannot be used as a boolean; test for '!= 0' instead}}
445
+ }
446
+
447
+ // labeled variadics after labeled parameter
448
+ func f5( _ a: Bool = false , b: String = " " , c: Int ... , d: [ Int ] = [ ] ) { }
449
+
450
+ func test_f5( ) {
451
+ f5 ( true , b: " 2 " , c: 31 , 32 , 33 , d: [ 4 ] )
452
+
453
+ f5 ( true , b: " 2 " , c: " 31 " , 32 , 33 , d: [ 4 ] ) // expected-error {{cannot convert value of type 'String' to expected argument type 'Int'}}
454
+
455
+ f5 ( true , b: " 2 " , c: 31 , " 32 " , 33 , d: [ 4 ] ) // expected-error {{cannot convert value of type 'String' to expected argument type 'Int'}}
456
+
457
+ f5 ( true , b: " 2 " , c: 31 , 32 , " 33 " , d: [ 4 ] ) // expected-error {{cannot convert value of type 'String' to expected argument type 'Int'}}
458
+
459
+ f5 ( true , b: " 2 " , c: 31 , 32 , d: [ 4 ] )
460
+ f5 ( true , b: " 2 " , c: 31 , d: [ 4 ] )
461
+ f5 ( true , b: " 2 " , d: [ 4 ] )
462
+
463
+ f5 ( true , c: 31 , b: " 2 " , d: [ 4 ] ) // expected-error {{argument 'b' must precede argument 'c'}}
464
+
465
+ f5 ( true , b: " 2 " , d: [ 4 ] , 31 ) // expected-error {{incorrect argument labels in call (have '_:b:d:_:', expected '_:b:c:d:')}}
466
+
467
+ f5 ( true , b: " 2 " , c: 31 )
468
+ f5 ( true , b: " 2 " )
469
+
470
+ f5 ( true )
471
+ f5 ( true , c: 31 )
472
+ f5 ( true , c: 31 , d: [ 4 ] )
473
+ f5 ( true , c: 31 , 32 )
474
+ f5 ( true , c: 31 , 32 , d: [ 4 ] )
475
+
476
+ f5 ( b: " 2 " , c: 31 , 32 , 33 , d: [ 4 ] )
477
+
478
+ f5 ( b: " 2 " , c: " 31 " , 32 , 33 , d: [ 4 ] ) // expected-error {{cannot convert value of type 'String' to expected argument type 'Int'}}
479
+
480
+ f5 ( b: " 2 " , c: 31 , " 32 " , 33 , d: [ 4 ] ) // expected-error {{cannot convert value of type 'String' to expected argument type 'Int'}}
481
+
482
+ f5 ( b: " 2 " , c: 31 , 32 , " 33 " , d: [ 4 ] ) // expected-error {{cannot convert value of type 'String' to expected argument type 'Int'}}
483
+
484
+ f5 ( b: " 2 " , c: 31 , 32 , d: [ 4 ] )
485
+ f5 ( b: " 2 " , c: 31 , d: [ 4 ] )
486
+ f5 ( b: " 2 " , d: [ 4 ] )
487
+
488
+ f5 ( c: 31 , b: " 2 " , d: [ 4 ] ) // expected-error {{incorrect argument labels in call (have 'c:b:d:', expected '_:b:c:d:')}}
489
+
490
+ f5 ( b: " 2 " , d: [ 4 ] , c: 31 ) // expected-error {{incorrect argument labels in call (have 'b:d:c:', expected '_:b:c:d:')}}
491
+
492
+ f5 ( b: " 2 " , c: 31 )
493
+ f5 ( b: " 2 " , c: 31 , 32 )
494
+ f5 ( b: " 2 " )
495
+
496
+ f5 ( )
497
+ f5 ( c: 31 )
498
+ f5 ( c: 31 , d: [ 4 ] )
499
+ f5 ( c: 31 , 32 )
500
+ f5 ( c: 31 , 32 , d: [ 4 ] )
501
+ }
502
+ }
503
+
243
504
// -------------------------------------------
244
505
// Missing arguments
245
506
// -------------------------------------------
0 commit comments