@@ -134,6 +134,16 @@ fun_31849281(a: { !$0 }, c: [nil, 42], b: { (num: Int) -> String in return Strin
134
134
fun_31849281 ( a: { !$0 } , c: [ nil , 42 ] , b: { " \( $0) " } )
135
135
// expected-error @-1 {{argument 'b' must precede argument 'c'}} {{26-26=b: { "\\($0)" }, }} {{38-54=}}
136
136
137
+ struct ReorderAndAllLabels {
138
+ func f( aa: Int , bb: Int , cc: Int , dd: Int ) { }
139
+
140
+ func test( ) {
141
+ f ( bb: 1 , ccx: 2 , ddx: 3 , aa: 0 ) // expected-error {{argument 'aa' must precede argument 'bb'}} {{28-35=}} {{7-7=aa: 0, }} {{none}}
142
+
143
+ f ( bbx: 1 , ccx: 2 , ddx: 3 , aa: 0 ) // expected-error {{incorrect argument labels in call (have 'bbx:ccx:ddx:aa:', expected 'aa:bb:cc:dd:')}} {{7-10=aa}} {{15-18=bb}} {{23-26=cc}} {{31-33=dd}} {{none}}
144
+ }
145
+ }
146
+
137
147
// -------------------------------------------
138
148
// Default arguments
139
149
// -------------------------------------------
@@ -176,6 +186,16 @@ defargs2(first: 1, last: 4, x: 1) // expected-error{{argument 'x' must precede a
176
186
func rdar43525641( _ a: Int , _ b: Int = 0 , c: Int = 0 , _ d: Int ) { }
177
187
rdar43525641 ( 1 , c: 2 , 3 ) // Ok
178
188
189
+ func testLabelErrorDefault( ) {
190
+ func f( aa: Int , bb: Int , cc: Int = 0 ) { }
191
+
192
+ f ( aax: 0 , bbx: 1 , cc: 2 )
193
+ // expected-error@-1 {{incorrect argument labels in call (have 'aax:bbx:cc:', expected 'aa:bb:cc:')}}
194
+
195
+ f ( aax: 0 , bbx: 1 )
196
+ // expected-error@-1 {{incorrect argument labels in call (have 'aax:bbx:', expected 'aa:bb:')}}
197
+ }
198
+
179
199
// -------------------------------------------
180
200
// Variadics
181
201
// -------------------------------------------
@@ -386,6 +406,16 @@ struct Variadics8 {
386
406
func var_31849281( _ a: Int , _ b: Int ... , c: Int ) { }
387
407
var_31849281 ( 1 , c: 10 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ) // expected-error {{unnamed argument #3 must precede argument 'c'}} {{17-17=3, 4, 5, 6, 7, 8, 9, }} {{22-43=}}
388
408
409
+ func testLabelErrorVariadic( ) {
410
+ func f( aa: Int , bb: Int , cc: Int ... ) { }
411
+
412
+ f ( aax: 0 , bbx: 1 , cc: 2 , 3 , 4 )
413
+ // expected-error@-1 {{incorrect argument labels in call (have 'aax:bbx:cc:_:_:', expected 'aa:bb:cc:_:_:')}}
414
+
415
+ f ( aax: 0 , bbx: 1 )
416
+ // expected-error@-1 {{incorrect argument labels in call (have 'aax:bbx:', expected 'aa:bb:')}}
417
+ }
418
+
389
419
// -------------------------------------------
390
420
// Positions around defaults and variadics
391
421
// -------------------------------------------
@@ -652,6 +682,115 @@ struct PositionsAroundDefaultsAndVariadics {
652
682
}
653
683
}
654
684
685
+ // -------------------------------------------
686
+ // Matching position of unlabeled parameters
687
+ // -------------------------------------------
688
+
689
+ func testUnlabeledParameterBindingPosition( ) {
690
+ do {
691
+ func f( _ aa: Int ) { }
692
+
693
+ f ( 0 , 1 )
694
+ // expected-error@-1:10 {{extra argument in call}}
695
+ }
696
+
697
+ do {
698
+ // expected-note@+1 *{{'f(aa:_:)' declared here}}
699
+ func f( aa: Int , _ bb: Int ) { }
700
+
701
+ f ( 1 )
702
+ // expected-error@-1 {{missing argument for parameter 'aa' in call}}
703
+
704
+ f ( 0 , 1 )
705
+ // expected-error@-1:6 {{missing argument label 'aa:' in call}}
706
+
707
+ f ( 0 , xx: 1 )
708
+ // expected-error@-1:7 {{missing argument for parameter 'aa' in call}}
709
+ // expected-error@-2:14 {{extra argument 'xx' in call}}
710
+
711
+ f ( xx: 0 , 1 )
712
+ // expected-error@-1:7 {{missing argument for parameter 'aa' in call}}
713
+ // expected-error@-2:14 {{extra argument in call}}
714
+
715
+ f ( 0 , 1 , 9 )
716
+ // expected-error@-1:13 {{extra argument in call}}
717
+
718
+ f ( 0 , 1 , xx: 9 )
719
+ // expected-error@-1:17 {{extra argument 'xx' in call}}
720
+
721
+ f ( xx: 91 , 1 , 92 )
722
+ // expected-error@-1 {{extra arguments at positions #2, #3 in call}}
723
+ // expected-error@-2 {{missing argument for parameter 'aa' in call}}
724
+ }
725
+
726
+ do {
727
+ func f( _ aa: Int , bb: Int , _ cc: Int ) { }
728
+
729
+ f ( bb: 1 , 0 , 2 )
730
+ // expected-error@-1 {{unnamed argument #3 must precede argument 'bb'}}
731
+ }
732
+
733
+ do {
734
+ func f( _ aa: Int = 80 , bb: Int , _ cc: Int ) { }
735
+
736
+ f ( bb: 1 , 2 ) // ok
737
+ }
738
+
739
+ do {
740
+ // expected-note@+1 *{{'f(_:bb:_:)' declared here}}
741
+ func f( _ aa: Int , bb: Int , _ cc: Int ... ) { }
742
+
743
+ f ( bb: 1 , 2 , 3 , 4 )
744
+ // expected-error@-1 {{missing argument for parameter #1 in call}}
745
+ }
746
+
747
+ do {
748
+ func f( _ aa: Int , bb: Int = 81 , _ cc: Int ... ) { }
749
+
750
+ f ( 0 , 2 , 3 ) // ok
751
+ }
752
+
753
+ do {
754
+ // expected-note@+1 *{{'f(aa:_:_:)' declared here}}
755
+ func f( aa: Int , _ bb: Int , _ cc: Int ) { }
756
+
757
+ f ( 0 , 1 )
758
+ // expected-error@-1:7 {{missing argument for parameter 'aa' in call}}
759
+ }
760
+
761
+ do {
762
+ // expected-note@+1 *{{'f(aa:_:_:)' declared here}}
763
+ func f( aa: Int , _ bb: Int = 81 , _ cc: Int ) { }
764
+
765
+ f ( 0 , 1 )
766
+ // expected-error@-1:7 {{missing argument for parameter 'aa' in call}}
767
+ }
768
+
769
+ do {
770
+ // expected-note@+1 *{{'f(aa:bb:_:)' declared here}}
771
+ func f( aa: Int , bb: Int , _ cc: Int ) { }
772
+
773
+ f ( 0 , 2 )
774
+ // expected-error@-1:6 {{missing argument labels 'aa:bb:' in call}}
775
+ // expected-error@-2:8 {{missing argument for parameter 'bb' in call}}
776
+
777
+ f ( 0 , bb: 1 , 2 )
778
+ // expected-error@-1:6 {{missing argument label 'aa:' in call}}
779
+ }
780
+
781
+ do {
782
+ func f( _ aa: Int , _ bb: Int = 81 , cc: Int , _ dd: Int ) { }
783
+
784
+ f ( 0 , cc: 2 , 3 ) // ok
785
+ }
786
+
787
+ do {
788
+ func f( _ aa: Int , _ bb: Int = 81 , cc: Int = 82 , _ dd: Int ) { }
789
+
790
+ f ( 0 , cc: 2 , 3 ) // ok
791
+ }
792
+ }
793
+
655
794
// -------------------------------------------
656
795
// Missing arguments
657
796
// -------------------------------------------
@@ -894,6 +1033,19 @@ mismatchOverloaded1.method1(5, secondArg: nil)
894
1033
// Prefer available to unavailable declaration, if it comes up.
895
1034
mismatchOverloaded1. method2 ( 5 ) { $0 }
896
1035
1036
+ struct RelabelAndTrailingClosure {
1037
+ func f1( aa: Int , bb: Int , cc: ( ) -> Void = { } ) { }
1038
+ func f2( aa: Int , bb: Int , _ cc: ( ) -> Void = { } ) { }
1039
+
1040
+ func test( ) {
1041
+ f1 ( aax: 1 , bbx: 2 ) { } // expected-error {{incorrect argument labels in call (have 'aax:bbx:_:', expected 'aa:bb:cc:')}} {{8-11=aa}} {{16-19=bb}} {{none}}
1042
+ f2 ( aax: 1 , bbx: 2 ) { } // expected-error {{incorrect argument labels in call (have 'aax:bbx:_:', expected 'aa:bb:_:')}} {{8-11=aa}} {{16-19=bb}} {{none}}
1043
+
1044
+ f1 ( aax: 1 , bbx: 2 ) // expected-error {{incorrect argument labels in call (have 'aax:bbx:', expected 'aa:bb:')}} {{8-11=aa}} {{16-19=bb}} {{none}}
1045
+ f2 ( aax: 1 , bbx: 2 ) // expected-error {{incorrect argument labels in call (have 'aax:bbx:', expected 'aa:bb:')}} {{8-11=aa}} {{16-19=bb}} {{none}}
1046
+ }
1047
+ }
1048
+
897
1049
// -------------------------------------------
898
1050
// Values of function type
899
1051
// -------------------------------------------
@@ -1035,3 +1187,65 @@ CurriedClass.m1(2, b: 42) // expected-error {{instance member 'm1' cannot be u
1035
1187
1036
1188
// <rdar://problem/22108559> QoI: Confusing error message when calling an instance method as a class method
1037
1189
CurriedClass . m2 ( 12 ) // expected-error {{instance member 'm2' cannot be used on type 'CurriedClass'; did you mean to use a value of this type instead?}}
1190
+
1191
+ // -------------------------------------------
1192
+ // Multiple label errors
1193
+ // -------------------------------------------
1194
+
1195
+ func testLabelErrorsBasic( ) {
1196
+ func f( _ aa: Int , _ bb: Int , cc: Int , dd: Int , ee: Int , ff: Int ) { }
1197
+
1198
+ // 1 wrong
1199
+ f ( 0 , 1 , ccx: 2 , dd: 3 , ee: 4 , ff: 5 )
1200
+ // expected-error@-1 {{incorrect argument label in call (have '_:_:ccx:dd:ee:ff:', expected '_:_:cc:dd:ee:ff:')}} {{11-14=cc}} {{none}}
1201
+
1202
+ // 1 missing
1203
+ f ( 0 , 1 , 2 , dd: 3 , ee: 4 , ff: 5 )
1204
+ // expected-error@-1 {{missing argument label 'cc:' in call}} {{11-11=cc: }} {{none}}
1205
+
1206
+ // 1 extra
1207
+ f ( aa: 0 , 1 , cc: 2 , dd: 3 , ee: 4 , ff: 5 )
1208
+ // expected-error@-1 {{extraneous argument label 'aa:' in call}} {{5-9=}} {{none}}
1209
+
1210
+ // 1 ooo
1211
+ f ( 0 , 1 , dd: 3 , cc: 2 , ee: 4 , ff: 5 )
1212
+ // expected-error@-1 {{argument 'cc' must precede argument 'dd'}} {{16-23=}} {{11-11=cc: 2, }} {{none}}
1213
+
1214
+ // 2 wrong
1215
+ f ( 0 , 1 , ccx: 2 , ddx: 3 , ee: 4 , ff: 5 )
1216
+ // expected-error@-1 {{incorrect argument labels in call (have '_:_:ccx:ddx:ee:ff:', expected '_:_:cc:dd:ee:ff:')}} {{11-14=cc}} {{19-22=dd}} {{none}}
1217
+
1218
+ // 2 missing
1219
+ f ( 0 , 1 , 2 , 3 , ee: 4 , ff: 5 )
1220
+ // expected-error@-1 {{missing argument labels 'cc:dd:' in call}} {{11-11=cc: }} {{14-14=dd: }} {{none}}
1221
+
1222
+ // 2 extra
1223
+ f ( aa: 0 , bb: 1 , cc: 2 , dd: 3 , ee: 4 , ff: 5 )
1224
+ // expected-error@-1 {{extraneous argument labels 'aa:bb:' in call}} {{5-9=}} {{12-16=}} {{none}}
1225
+
1226
+ // 2 ooo
1227
+ f ( 0 , 1 , dd: 3 , cc: 2 , ff: 5 , ee: 4 )
1228
+ // expected-error@-1 {{argument 'cc' must precede argument 'dd'}} {{16-23=}} {{11-11=cc: 2, }} {{none}}
1229
+
1230
+ // 1 wrong + 1 missing
1231
+ f ( 0 , 1 , ccx: 2 , 3 , ee: 4 , ff: 5 )
1232
+ // expected-error@-1 {{incorrect argument labels in call (have '_:_:ccx:_:ee:ff:', expected '_:_:cc:dd:ee:ff:')}} {{11-14=cc}} {{19-19=dd: }} {{none}}
1233
+
1234
+ // 1 wrong + 1 extra
1235
+ f ( aa: 0 , 1 , ccx: 2 , dd: 3 , ee: 4 , ff: 5 )
1236
+ // expected-error@-1 {{incorrect argument labels in call (have 'aa:_:ccx:dd:ee:ff:', expected '_:_:cc:dd:ee:ff:')}} {{5-9=}} {{15-18=cc}} {{none}}
1237
+
1238
+ // 1 wrong + 1 ooo
1239
+ f ( 0 , 1 , ccx: 2 , dd: 3 , ff: 5 , ee: 4 )
1240
+ // expected-error@-1 {{incorrect argument labels in call (have '_:_:ccx:dd:ff:ee:', expected '_:_:cc:dd:ee:ff:')}} {{11-14=cc}} {{26-28=ee}} {{33-35=ff}} {{none}}
1241
+ }
1242
+
1243
+ struct DiagnoseAllLabels {
1244
+ func f( aa: Int , bb: Int , cc: Int ... , dd: Int , ee: Int = 0 , ff: Int = 0 ) { }
1245
+
1246
+ func test( ) {
1247
+ f ( aax: 0 , bbx: 1 , cc: 21 , 22 , 23 , dd: 3 , ff: 5 ) // expected-error {{incorrect argument labels in call (have 'aax:bbx:cc:_:_:dd:ff:', expected 'aa:bb:cc:_:_:dd:ff:')}} {{7-10=aa}} {{15-18=bb}} {{none}}
1248
+
1249
+ f ( aax: 0 , bbx: 1 , dd: 3 , ff: 5 ) // expected-error {{incorrect argument labels in call (have 'aax:bbx:dd:ff:', expected 'aa:bb:dd:ff:')}} {{7-10=aa}} {{15-18=bb}} {{none}}
1250
+ }
1251
+ }
0 commit comments