@@ -66,6 +66,13 @@ class GenericCtor<U> {
66
66
}
67
67
GenericCtor < Int > ( ) // expected-error{{missing argument for parameter 't' in call}}
68
68
69
+ func secondArgumentNotLabeled( a: Int , _ b: Int ) { }
70
+ secondArgumentNotLabeled ( 10 , 20 )
71
+ // expected-error@-1 {{missing argument label 'a:' in call}}
72
+
73
+ func f_31849281( x: Int , y: Int , z: Int ) { }
74
+ f_31849281 ( 42 , y: 10 , x: 20 ) // expected-error {{incorrect argument labels in call (have '_:y:x:', expected 'x:y:z:')}} {{12-12=x: }} {{23-24=z}}
75
+
69
76
// -------------------------------------------
70
77
// Extraneous keywords
71
78
// -------------------------------------------
@@ -82,12 +89,51 @@ somekeywords1(x: 1, y: 2, z: 3) // expected-error{{extraneous argument label 'x:
82
89
somekeywords1 ( 1 , 2 , 3 ) // expected-error{{missing argument labels 'y:z:' in call}}{{18-18=y: }}{{21-21=z: }}
83
90
somekeywords1 ( x: 1 , 2 , z: 3 ) // expected-error{{incorrect argument labels in call (have 'x:_:z:', expected '_:y:z:')}}{{15-18=}}{{21-21=y: }}
84
91
92
+ // SR-2242: poor diagnostic when argument label is omitted
93
+
94
+ func r27212391( x: Int , _ y: Int ) {
95
+ let _: Int = x + y
96
+ }
97
+
98
+ func r27212391( a: Int , x: Int , _ y: Int ) {
99
+ let _: Int = a + x + y
100
+ }
101
+
102
+ r27212391 ( 3 , 5 ) // expected-error {{missing argument label 'x:' in call}}
103
+ r27212391 ( 3 , y: 5 ) // expected-error {{incorrect argument labels in call (have '_:y:', expected 'x:_:')}}
104
+ r27212391 ( 3 , x: 5 ) // expected-error {{argument 'x' must precede unnamed argument #1}} {{11-11=x: 5, }} {{12-18=}}
105
+ r27212391 ( y: 3 , x: 5 ) // expected-error {{incorrect argument labels in call (have 'y:x:', expected 'x:_:')}} {{11-12=x}} {{17-20=}}
106
+ r27212391 ( y: 3 , 5 ) // expected-error {{incorrect argument label in call (have 'y:_:', expected 'x:_:')}}
107
+ r27212391 ( x: 3 , x: 5 ) // expected-error {{extraneous argument label 'x:' in call}}
108
+ r27212391 ( a: 1 , 3 , y: 5 ) // expected-error {{incorrect argument labels in call (have 'a:_:y:', expected 'a:x:_:')}}
109
+ r27212391 ( 1 , x: 3 , y: 5 ) // expected-error {{incorrect argument labels in call (have '_:x:y:', expected 'a:x:_:')}}
110
+ r27212391 ( a: 1 , y: 3 , x: 5 ) // expected-error {{incorrect argument labels in call (have 'a:y:x:', expected 'a:x:_:')}}
111
+ r27212391 ( a: 1 , 3 , x: 5 ) // expected-error {{argument 'x' must precede unnamed argument #2}} {{17-17=x: 5, }} {{18-24=}}
85
112
86
113
// -------------------------------------------
87
114
// Out-of-order keywords
88
115
// -------------------------------------------
89
116
allkeywords1 ( y: 1 , x: 2 ) // expected-error{{argument 'x' must precede argument 'y'}} {{14-14=x: 2, }} {{18-24=}}
90
117
118
+ // rdar://problem/31849281 - Let's play "bump the argument"
119
+
120
+ struct rdar31849281 { var foo , a , b , c : Int }
121
+ _ = rdar31849281 ( a: 101 , b: 102 , c: 103 , foo: 104 ) // expected-error {{argument 'foo' must precede argument 'a'}} {{18-18=foo: 104, }} {{40-50=}}
122
+
123
+ _ = rdar31849281 ( a: 101 , c: 103 , b: 102 , foo: 104 ) // expected-error {{argument 'foo' must precede argument 'a'}} {{18-18=foo: 104, }} {{40-50=}}
124
+ _ = rdar31849281 ( foo: 104 , a: 101 , c: 103 , b: 102 ) // expected-error {{argument 'b' must precede argument 'c'}} {{36-36=b: 102, }} {{42-50=}}
125
+
126
+ _ = rdar31849281 ( b: 102 , c: 103 , a: 101 , foo: 104 ) // expected-error {{incorrect argument labels in call (have 'b:c:a:foo:', expected 'foo:a:b:c:')}} {{18-19=foo}} {{26-27=a}} {{34-35=b}} {{42-45=c}}
127
+ _ = rdar31849281 ( foo: 104 , b: 102 , c: 103 , a: 101 ) // expected-error {{argument 'a' must precede argument 'b'}} {{28-28=a: 101, }} {{42-50=}}
128
+
129
+ func fun_31849281( a: ( Bool ) -> Bool , b: ( Int ) -> ( String ) , c: [ Int ? ] ) { }
130
+ fun_31849281 ( c: [ nil , 42 ] , a: { !$0 } , b: { ( num: Int ) -> String in return " \( num) " } )
131
+ // expected-error @-1 {{incorrect argument labels in call (have 'c:a:b:', expected 'a:b:c:')}} {{14-15=a}} {{28-29=b}} {{40-41=c}}
132
+ fun_31849281 ( a: { !$0 } , c: [ nil , 42 ] , b: { ( num: Int ) -> String in return String ( describing: num) } )
133
+ // expected-error @-1 {{argument 'b' must precede argument 'c'}} {{26-26=b: { (num: Int) -> String in return String(describing: num) }, }} {{38-101=}}
134
+ fun_31849281 ( a: { !$0 } , c: [ nil , 42 ] , b: { " \( $0) " } )
135
+ // expected-error @-1 {{argument 'b' must precede argument 'c'}} {{26-26=b: { "\\($0)" }, }} {{38-54=}}
136
+
91
137
// -------------------------------------------
92
138
// Default arguments
93
139
// -------------------------------------------
@@ -127,6 +173,9 @@ defargs2(first: 1, z: 3, y: 2, last: 4) // expected-error{{argument 'y' must pre
127
173
defargs2 ( x: 1 , first: 1 , last: 4 ) // expected-error{{argument 'first' must precede argument 'x'}} {{10-10=first: 1, }} {{14-24=}}
128
174
defargs2 ( first: 1 , last: 4 , x: 1 ) // expected-error{{argument 'x' must precede argument 'last'}} {{20-20=x: 1, }} {{27-33=}}
129
175
176
+ func rdar43525641( _ a: Int , _ b: Int = 0 , c: Int = 0 , _ d: Int ) { }
177
+ rdar43525641 ( 1 , c: 2 , 3 ) // Ok
178
+
130
179
// -------------------------------------------
131
180
// Variadics
132
181
// -------------------------------------------
@@ -334,6 +383,9 @@ struct Variadics8 {
334
383
}
335
384
}
336
385
386
+ func var_31849281( _ a: Int , _ b: Int ... , c: Int ) { }
387
+ 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
+
337
389
// -------------------------------------------
338
390
// Positions around defaults and variadics
339
391
// -------------------------------------------
@@ -630,6 +682,18 @@ mismatch1(foo: 5) // expected-error {{extra argument 'foo' in call}}
630
682
mismatch1 ( baz: 1 , wobble: 2 ) // expected-error{{incorrect argument labels in call (have 'baz:wobble:', expected 'bar:wibble:')}} {{11-14=bar}} {{19-25=wibble}}
631
683
mismatch1 ( food: 1 , zap: 2 ) // expected-error{{extra arguments at positions #1, #2 in call}}
632
684
685
+ // <rdar://problem/27891805> QoI: FailureDiagnosis doesn't look through 'try'
686
+ struct rdar27891805 {
687
+ init ( contentsOf: String , encoding: String ) throws { }
688
+ init ( contentsOf: String , usedEncoding: inout String ) throws { }
689
+ init < T> ( _ t: T ) { }
690
+ }
691
+
692
+ try rdar27891805 ( contentsOfURL: nil , usedEncoding: nil )
693
+ // expected-error@-1 {{incorrect argument label in call (have 'contentsOfURL:usedEncoding:', expected 'contentsOf:usedEncoding:')}}
694
+ // expected-error@-2 {{'nil' is not compatible with expected argument type 'String'}}
695
+ // expected-error@-3 {{'nil' is not compatible with expected argument type 'String'}}
696
+
633
697
// -------------------------------------------
634
698
// Out of order and default
635
699
// -------------------------------------------
@@ -874,3 +938,100 @@ func generic_and_missing_label<T>(x: T) {}
874
938
875
939
generic_and_missing_label ( 42 )
876
940
// expected-error@-1 {{missing argument label 'x:' in call}} {{27-27=x: }}
941
+
942
+ // -------------------------------------------
943
+ // Curried functions
944
+ // -------------------------------------------
945
+
946
+ func f7( _ a: Int ) -> ( _ b: Int ) -> Int {
947
+ return { b in a+ b }
948
+ }
949
+
950
+ _ = f7 ( 1 ) ( 1 )
951
+ f7 ( 1.0 ) ( 2 ) // expected-error {{cannot convert value of type 'Double' to expected argument type 'Int'}}
952
+
953
+ f7 ( 1 ) ( 1.0 ) // expected-error {{cannot convert value of type 'Double' to expected argument type 'Int'}}
954
+ f7 ( 1 ) ( b: 1.0 ) // expected-error{{extraneous argument label 'b:' in call}}
955
+ // expected-error@-1 {{cannot convert value of type 'Double' to expected argument type 'Int'}}
956
+
957
+ let f10 = f7 ( 2 )
958
+ _ = f10 ( 1 )
959
+ f10 ( 10 ) // expected-warning {{result of call to function returning 'Int' is unused}}
960
+ f10 ( 1.0 ) // expected-error {{cannot convert value of type 'Double' to expected argument type 'Int'}}
961
+ f10 ( b: 1.0 ) // expected-error {{extraneous argument label 'b:' in call}}
962
+ // expected-error@-1 {{cannot convert value of type 'Double' to expected argument type 'Int'}}
963
+
964
+
965
+ class CurriedClass {
966
+ func method1( ) { }
967
+ func method2( _ a: Int ) -> ( _ b : Int ) -> ( ) { return { b in ( ) } }
968
+ func method3( _ a: Int , b : Int ) { } // expected-note 3 {{'method3(_:b:)' declared here}}
969
+ }
970
+
971
+ let c = CurriedClass ( )
972
+ _ = c. method1
973
+ c. method1 ( 1 ) // expected-error {{argument passed to call that takes no arguments}}
974
+ _ = c. method2 ( 1 )
975
+ _ = c. method2 ( 1.0 ) // expected-error {{cannot convert value of type 'Double' to expected argument type 'Int'}}
976
+ c. method2 ( 1 ) ( 2 )
977
+ c. method2 ( 1 ) ( c: 2 ) // expected-error {{extraneous argument label 'c:' in call}}
978
+ c. method2 ( 1 ) ( c: 2.0 ) // expected-error {{extraneous argument label 'c:' in call}}
979
+ // expected-error@-1 {{cannot convert value of type 'Double' to expected argument type 'Int'}}
980
+ c. method2 ( 1 ) ( 2.0 ) // expected-error {{cannot convert value of type 'Double' to expected argument type 'Int'}}
981
+ c. method2 ( 1.0 ) ( 2 ) // expected-error {{cannot convert value of type 'Double' to expected argument type 'Int'}}
982
+ c. method2 ( 1.0 ) ( 2.0 ) // expected-error {{cannot convert value of type 'Double' to expected argument type 'Int'}}
983
+ // expected-error@-1 {{cannot convert value of type 'Double' to expected argument type 'Int'}}
984
+
985
+ CurriedClass . method1 ( c) ( )
986
+ _ = CurriedClass . method1 ( c)
987
+ CurriedClass . method1 ( c) ( 1 ) // expected-error {{argument passed to call that takes no arguments}}
988
+ CurriedClass . method1 ( 2.0 ) ( 1 ) // expected-error {{cannot convert value of type 'Double' to expected argument type 'CurriedClass'}}
989
+ // expected-error@-1:27 {{argument passed to call that takes no arguments}}
990
+
991
+ CurriedClass . method2 ( c) ( 32 ) ( b: 1 ) // expected-error{{extraneous argument label 'b:' in call}}
992
+ _ = CurriedClass . method2 ( c)
993
+ _ = CurriedClass . method2 ( c) ( 32 )
994
+ _ = CurriedClass . method2 ( 1 , 2 ) // expected-error {{extra argument in call}}
995
+ // expected-error@-1 {{instance member 'method2' cannot be used on type 'CurriedClass'; did you mean to use a value of this type instead?}}
996
+ CurriedClass . method2 ( c) ( 1.0 ) ( b: 1 ) // expected-error {{cannot convert value of type 'Double' to expected argument type 'Int'}}
997
+ // expected-error@-1 {{extraneous argument label 'b:' in call}}
998
+ CurriedClass . method2 ( c) ( 1 ) ( 1.0 ) // expected-error {{cannot convert value of type 'Double' to expected argument type 'Int'}}
999
+ CurriedClass . method2 ( c) ( 2 ) ( c: 1.0 ) // expected-error {{extraneous argument label 'c:'}}
1000
+ // expected-error@-1 {{cannot convert value of type 'Double' to expected argument type 'Int'}}
1001
+
1002
+ CurriedClass . method3 ( c) ( 32 , b: 1 )
1003
+ _ = CurriedClass . method3 ( c)
1004
+ _ = CurriedClass . method3 ( c) ( 1 , 2 ) // expected-error {{missing argument label 'b:' in call}} {{32-32=b: }}
1005
+ _ = CurriedClass . method3 ( c) ( 1 , b: 2 ) ( 32 ) // expected-error {{cannot call value of non-function type '()'}}
1006
+ _ = CurriedClass . method3 ( 1 , 2 ) // expected-error {{instance member 'method3' cannot be used on type 'CurriedClass'; did you mean to use a value of this type instead?}}
1007
+ // expected-error@-1 {{missing argument label 'b:' in call}}
1008
+ CurriedClass . method3 ( c) ( 1.0 , b: 1 ) // expected-error {{cannot convert value of type 'Double' to expected argument type 'Int'}}
1009
+ CurriedClass . method3 ( c) ( 1 ) // expected-error {{missing argument for parameter 'b' in call}}
1010
+ CurriedClass . method3 ( c) ( c: 1.0 ) // expected-error {{incorrect argument labels in call (have 'c:', expected '_:b:')}}
1011
+ // expected-error@-1 {{cannot convert value of type 'Double' to expected argument type 'Int'}}
1012
+ // expected-error@-2 {{missing argument for parameter #1 in call}}
1013
+
1014
+
1015
+ extension CurriedClass {
1016
+ func f( ) {
1017
+ method3 ( 1 , b: 2 )
1018
+ method3 ( ) // expected-error {{missing arguments for parameters #1, 'b' in call}} {{13-13=<#Int#>, b: <#Int#>}}
1019
+ method3 ( 42 ) // expected-error {{missing argument for parameter 'b' in call}}
1020
+ method3 ( self )
1021
+ // expected-error@-1:13 {{cannot convert value of type 'CurriedClass' to expected argument type 'Int'}}
1022
+ // expected-error@-2:17 {{missing argument for parameter 'b' in call}} {{17-17=, b: <#Int#>}}
1023
+ }
1024
+ }
1025
+
1026
+ extension CurriedClass {
1027
+ func m1( _ a : Int , b : Int ) { }
1028
+
1029
+ func m2( _ a : Int ) { }
1030
+ }
1031
+
1032
+ // <rdar://problem/23718816> QoI: "Extra argument" error when accidentally currying a method
1033
+ CurriedClass . m1 ( 2 , b: 42 ) // expected-error {{instance member 'm1' cannot be used on type 'CurriedClass'; did you mean to use a value of this type instead?}}
1034
+
1035
+
1036
+ // <rdar://problem/22108559> QoI: Confusing error message when calling an instance method as a class method
1037
+ 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?}}
0 commit comments