Skip to content

Commit dc8216e

Browse files
committed
[CSDiagnostics] Update shouldHaveDirectCalleeOverload
Given we can now find overloads for applies of optional functions, adjust the logic so we look at the call's direct callee. In addition, tweak the logic so we don't assert on a ForceTryExpr.
1 parent 8e0ec8d commit dc8216e

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ Type FailureDiagnostic::resolveInterfaceType(Type type,
158158

159159
/// Given an apply expr, returns true if it is expected to have a direct callee
160160
/// overload, resolvable using `getChoiceFor`. Otherwise, returns false.
161-
static bool shouldHaveDirectCalleeOverload(const ApplyExpr *apply) {
162-
auto *fnExpr = apply->getFn()->getValueProvidingExpr();
161+
static bool shouldHaveDirectCalleeOverload(const CallExpr *callExpr) {
162+
auto *fnExpr = callExpr->getDirectCallee();
163163

164164
// An apply of an apply/subscript doesn't have a direct callee.
165165
if (isa<ApplyExpr>(fnExpr) || isa<SubscriptExpr>(fnExpr))
@@ -169,11 +169,9 @@ static bool shouldHaveDirectCalleeOverload(const ApplyExpr *apply) {
169169
if (isa<ClosureExpr>(fnExpr))
170170
return false;
171171

172-
// If the optionality changes, there's no direct callee.
173-
if (isa<BindOptionalExpr>(fnExpr) || isa<ForceValueExpr>(fnExpr) ||
174-
isa<OptionalTryExpr>(fnExpr)) {
172+
// No direct callee for a try!/try?.
173+
if (isa<ForceTryExpr>(fnExpr) || isa<OptionalTryExpr>(fnExpr))
175174
return false;
176-
}
177175

178176
// If we have an intermediate cast, there's no direct callee.
179177
if (isa<ExplicitCastExpr>(fnExpr))

test/Constraints/function.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func returnsTakesEscapingFn() -> (@escaping () -> Int) -> Void { takesEscapingFn
169169
prefix operator ^^^
170170
prefix func ^^^(_ x: Int) -> (@escaping () -> Int) -> Void { takesEscapingFn }
171171

172-
func testWeirdFnExprs<T>(_ fn: () -> Int, _ cond: Bool, _ any: Any, genericArg: T) { // expected-note 11{{parameter 'fn' is implicitly non-escaping}}
172+
func testWeirdFnExprs<T>(_ fn: () -> Int, _ cond: Bool, _ any: Any, genericArg: T) { // expected-note 12{{parameter 'fn' is implicitly non-escaping}}
173173
(any as! (@escaping () -> Int) -> Void)(fn)
174174
// expected-error@-1 {{passing non-escaping parameter 'fn' to function expecting an @escaping closure}}
175175

@@ -183,6 +183,9 @@ func testWeirdFnExprs<T>(_ fn: () -> Int, _ cond: Bool, _ any: Any, genericArg:
183183
(^^^5)(fn)
184184
// expected-error@-1 {{passing non-escaping parameter 'fn' to function expecting an @escaping closure}}
185185

186+
(try! takesEscapingFn)(fn)
187+
// expected-error@-1 {{passing non-escaping parameter 'fn' to function expecting an @escaping closure}}
188+
186189
var optFn: Optional = takesEscapingFn
187190
optFn?(fn)
188191
// expected-error@-1 {{passing non-escaping parameter 'fn' to function expecting an @escaping closure}}

0 commit comments

Comments
 (0)