@@ -287,6 +287,23 @@ static bool isViableElement(ASTNode element,
287
287
using ElementInfo = std::tuple<ASTNode, ContextualTypeInfo,
288
288
/* isDiscarded=*/ bool , ConstraintLocator *>;
289
289
290
+ static TypeVariableType *assignClosureThrownErrorType (
291
+ ConstraintSystem &cs, ClosureExpr *closure) {
292
+ // FIXME: Remove this once the inference is working in general.
293
+ if (!cs.getASTContext ().LangOpts .hasFeature (Feature::FullTypedThrows))
294
+ return nullptr ;
295
+
296
+ auto closureType = cs.getClosureType (closure);
297
+ auto thrownType = closureType->getEffectiveThrownErrorTypeOrNever ();
298
+ auto computedThrownType = cs.inferCaughtErrorType (closure);
299
+ cs.addConstraint (
300
+ ConstraintKind::Conversion, computedThrownType, thrownType,
301
+ cs.getConstraintLocator (closure,
302
+ ConstraintLocator::ClosureThrownError));
303
+
304
+ return computedThrownType->getAs <TypeVariableType>();
305
+ }
306
+
290
307
static void createConjunction (ConstraintSystem &cs, DeclContext *dc,
291
308
ArrayRef<ElementInfo> elements,
292
309
ConstraintLocator *locator, bool isIsolated,
@@ -370,14 +387,16 @@ static void createConjunction(ConstraintSystem &cs, DeclContext *dc,
370
387
for (auto *externalVar : paramCollector.getTypeVars ())
371
388
referencedVars.push_back (externalVar);
372
389
390
+ #if false
373
391
// If the body of the closure is being used to infer the thrown error type
374
392
// of that closure, introduce a constraint to do so.
375
393
if (locator->directlyAt <ClosureExpr>()) {
376
394
auto *closure = castToExpr<ClosureExpr>(locator->getAnchor ());
377
- if (auto thrownErrorTypeVar = cs. getInferredThrownError ( closure))
395
+ if (auto thrownErrorTypeVar = assignClosureThrownErrorType (cs, closure))
378
396
referencedVars.push_back (thrownErrorTypeVar);
379
397
}
380
-
398
+ #endif
399
+
381
400
// It's possible that there are no viable elements in the body,
382
401
// because e.g. whole body is an `#if` statement or it only has
383
402
// declarations that are checked during solution application.
@@ -1137,9 +1156,9 @@ class SyntacticElementConstraintGenerator
1137
1156
}
1138
1157
1139
1158
if (closure) {
1140
- auto closureType = cs. getClosureType ( closure);
1159
+ assignClosureThrownErrorType (cs, closure);
1141
1160
}
1142
-
1161
+
1143
1162
return ;
1144
1163
}
1145
1164
0 commit comments