You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix <rdar://problem/23718816> QoI: "Extra argument" error when accidentally currying a method
It is a somewhat common case where folks are accidentally referring to an
instance member with the Type as the base. This forms a curried member,
which then produced head scratching error messages downstream.
Now that the prep work has gone in, the first part of this is now
straight-forward to fix: simply check for this case and diagnose it
with a custom error, which makes it more clear what the mistake was.
The other half of this problem (tracked by 22108559) affects cases where
the method you're calling takes a single argument. This isn't fixed
yet, but I'm adding a testcase for it anyway.
// <rdar://problem/20201968> QoI: poor diagnostic when calling a class method via a metatype
167
167
classr20201968C{
168
168
func blah(){
169
-
r20201968C.blah() // expected-error {{missing argument for parameter #1 in call}}
169
+
r20201968C.blah() // expected-error {{use of instance member 'blah' on type 'r20201968C'; did you mean to use a value of type 'r20201968C' instead?}}
170
170
}
171
171
}
172
172
@@ -344,7 +344,7 @@ CurriedClass.method1(2.0)(1) // expected-error {{cannot convert value of t
344
344
CurriedClass.method2(c)(32)(b:1)
345
345
_ =CurriedClass.method2(c)
346
346
_ =CurriedClass.method2(c)(32)
347
-
_ =CurriedClass.method2(1,2) // expected-error {{extra argument in call}}
347
+
_ =CurriedClass.method2(1,2) // expected-error {{use of instance member 'method2' on type 'CurriedClass'; did you mean to use a value of type 'CurriedClass' instead?}}
348
348
CurriedClass.method2(c)(1.0)(b:1) // expected-error {{cannot convert value of type 'Double' to expected argument type 'Int'}}
349
349
CurriedClass.method2(c)(1)(b:1.0) // expected-error {{cannot convert value of type 'Double' to expected argument type 'Int'}}
_ =CurriedClass.method3(c)(1, b:2)(32) // expected-error {{cannot call value of non-function type '()'}}
356
-
_ =CurriedClass.method3(1,2) // expected-error {{extra argument in call}}
356
+
_ =CurriedClass.method3(1,2) // expected-error {{use of instance member 'method3' on type 'CurriedClass'; did you mean to use a value of type 'CurriedClass' instead?}}
357
357
CurriedClass.method3(c)(1.0, b:1) // expected-error {{cannot convert value of type 'Double' to expected argument type 'Int'}}
358
358
CurriedClass.method3(c)(1) // expected-error {{missing argument for parameter 'b' in call}}
359
359
@@ -369,6 +369,22 @@ extension CurriedClass {
369
369
}
370
370
}
371
371
372
+
extensionCurriedClass{
373
+
func m1(a :Int, b :Int){}
374
+
375
+
func m2(a :Int){}
376
+
}
377
+
378
+
// <rdar://problem/23718816> QoI: "Extra argument" error when accidentally currying a method
379
+
CurriedClass.m1(2, b:42) // expected-error {{use of instance member 'm1' on type 'CurriedClass'; did you mean to use a value of type 'CurriedClass' instead?}}
380
+
381
+
382
+
// <rdar://problem/22108559> QoI: Confusing error message when calling an instance method as a class method
383
+
CurriedClass.m2(12) // expected-error {{cannot convert value of type 'Int' to expected argument type 'CurriedClass'}}
384
+
385
+
386
+
387
+
372
388
373
389
// <rdar://problem/19870975> Incorrect diagnostic for failed member lookups within closures passed as arguments ("(_) -> _")
0 commit comments