@@ -143,6 +143,37 @@ Type FailureDiagnostic::resolveInterfaceType(Type type,
143
143
: resolvedType;
144
144
}
145
145
146
+ // / Given an apply expr, returns true if it is expected to have a direct callee
147
+ // / overload, resolvable using `getChoiceFor`. Otherwise, returns false.
148
+ static bool shouldHaveDirectCalleeOverload (const ApplyExpr *apply) {
149
+ auto *fnExpr = apply->getFn ()->getValueProvidingExpr ();
150
+
151
+ // An apply of an apply/subscript doesn't have a direct callee.
152
+ if (isa<ApplyExpr>(fnExpr) || isa<SubscriptExpr>(fnExpr))
153
+ return false ;
154
+
155
+ // Applies of closures don't have callee overloads.
156
+ if (isa<ClosureExpr>(fnExpr))
157
+ return false ;
158
+
159
+ // If the optionality changes, there's no direct callee.
160
+ if (isa<BindOptionalExpr>(fnExpr) || isa<ForceValueExpr>(fnExpr) ||
161
+ isa<OptionalTryExpr>(fnExpr)) {
162
+ return false ;
163
+ }
164
+
165
+ // If we have an intermediate cast, there's no direct callee.
166
+ if (isa<ExplicitCastExpr>(fnExpr))
167
+ return false ;
168
+
169
+ // No direct callee for an if expr.
170
+ if (isa<IfExpr>(fnExpr))
171
+ return false ;
172
+
173
+ // Assume that anything else would have a direct callee.
174
+ return true ;
175
+ }
176
+
146
177
Optional<FunctionArgApplyInfo>
147
178
FailureDiagnostic::getFunctionArgApplyInfo (ConstraintLocator *locator) const {
148
179
auto &cs = getConstraintSystem ();
@@ -189,9 +220,11 @@ FailureDiagnostic::getFunctionArgApplyInfo(ConstraintLocator *locator) const {
189
220
rawFnType = overload->openedType ;
190
221
} else {
191
222
// If we didn't resolve an overload for the callee, we must be dealing with
192
- // an apply of an arbitrary function expr.
193
- auto *fnExpr = cast<CallExpr>(anchor)->getFn ();
194
- rawFnType = cs.getType (fnExpr)->getRValueType ();
223
+ // a call of an arbitrary function expr.
224
+ auto *call = cast<CallExpr>(anchor);
225
+ assert (!shouldHaveDirectCalleeOverload (call) &&
226
+ " Should we have resolved a callee for this?" );
227
+ rawFnType = cs.getType (call->getFn ())->getRValueType ();
195
228
}
196
229
197
230
auto *fnType = resolveType (rawFnType)->getAs <FunctionType>();
0 commit comments