File tree Expand file tree Collapse file tree 3 files changed +20
-10
lines changed Expand file tree Collapse file tree 3 files changed +20
-10
lines changed Original file line number Diff line number Diff line change @@ -224,20 +224,23 @@ FailureDiagnostic::getFunctionArgApplyInfo(ConstraintLocator *locator) const {
224
224
if (auto overload = getChoiceFor (anchor)) {
225
225
// If we have resolved an overload for the callee, then use that to get the
226
226
// function type and callee.
227
- if (auto *decl = overload->choice .getDeclOrNull ())
228
- callee = decl;
229
-
227
+ callee = overload->choice .getDeclOrNull ();
230
228
rawFnType = overload->openedType ;
231
229
} else {
232
230
// If we didn't resolve an overload for the callee, we must be dealing with
233
231
// a call of an arbitrary function expr.
234
232
auto *call = cast<CallExpr>(anchor);
235
233
assert (!shouldHaveDirectCalleeOverload (call) &&
236
234
" Should we have resolved a callee for this?" );
237
- rawFnType = cs.getType (call->getFn ())-> getRValueType () ;
235
+ rawFnType = cs.getType (call->getFn ());
238
236
}
239
237
240
- auto *fnType = resolveType (rawFnType)->getAs <FunctionType>();
238
+ // Try to resolve the function type by loading lvalues and looking through
239
+ // optional types, which can occur for expressions like `fn?(5)`.
240
+ auto *fnType = resolveType (rawFnType)
241
+ ->getRValueType ()
242
+ ->lookThroughAllOptionalTypes ()
243
+ ->getAs <FunctionType>();
241
244
if (!fnType)
242
245
return None;
243
246
Original file line number Diff line number Diff line change @@ -432,8 +432,15 @@ ConstraintLocator *ConstraintSystem::getCalleeLocator(Expr *expr) {
432
432
return getConstraintLocator (fnLocator,
433
433
ConstraintLocator::ConstructorMember);
434
434
}
435
- // Otherwise fall through and look for locators anchored on the fn expr.
436
- expr = fnExpr->getSemanticsProvidingExpr ();
435
+
436
+ // Otherwise fall through and look for locators anchored on the function
437
+ // expr. For CallExprs, this can look through things like parens and
438
+ // optional chaining.
439
+ if (auto *callExpr = dyn_cast<CallExpr>(expr)) {
440
+ expr = callExpr->getDirectCallee ();
441
+ } else {
442
+ expr = fnExpr;
443
+ }
437
444
}
438
445
439
446
if (auto *UDE = dyn_cast<UnresolvedDotExpr>(expr)) {
Original file line number Diff line number Diff line change @@ -10,8 +10,8 @@ class A {
10
10
@objc ( do_b_2: ) func do_b( _ x: Int ) { }
11
11
@objc func do_b( _ x: Float ) { }
12
12
13
- @objc func do_c( x: Int ) { }
14
- @objc func do_c( y: Int ) { }
13
+ @objc func do_c( x: Int ) { } // expected-note {{incorrect labels for candidate (have: '(_:)', expected: '(x:)')}}
14
+ @objc func do_c( y: Int ) { } // expected-note {{incorrect labels for candidate (have: '(_:)', expected: '(y:)')}}
15
15
}
16
16
17
17
func test0( _ a: AnyObject ) {
@@ -20,7 +20,7 @@ func test0(_ a: AnyObject) {
20
20
a. do_b ? ( 1 )
21
21
a. do_b ? ( 5.0 )
22
22
23
- a. do_c ? ( 1 ) // expected-error {{cannot invoke value of function type with argument list '(Int) '}}
23
+ a. do_c ? ( 1 ) // expected-error {{no exact matches in call to instance method 'do_c '}}
24
24
a. do_c ? ( x: 1 )
25
25
}
26
26
You can’t perform that action at this time.
0 commit comments