@@ -404,6 +404,30 @@ Type ConstraintSystem::openOpaqueType(Type type, ContextualTypePurpose context,
404
404
});
405
405
}
406
406
407
+ // / FIXME: This can be folded into its callers after a bit of cleanup.
408
+ static FunctionType *substGenericArgs (
409
+ GenericFunctionType *funcTy,
410
+ llvm::function_ref<Type(Type)> substFn) {
411
+ llvm::SmallVector<AnyFunctionType::Param, 4 > params;
412
+ params.reserve (funcTy->getNumParams ());
413
+
414
+ llvm::transform (funcTy->getParams (), std::back_inserter (params),
415
+ [&](const AnyFunctionType::Param ¶m) {
416
+ return param.withType (substFn (param.getPlainType ()));
417
+ });
418
+
419
+ auto resultTy = substFn (funcTy->getResult ());
420
+
421
+ Type thrownError = funcTy->getThrownError ();
422
+ if (thrownError)
423
+ thrownError = substFn (thrownError);
424
+
425
+ // Build the resulting (non-generic) function type.
426
+ return FunctionType::get (params, resultTy,
427
+ funcTy->getExtInfo ().withThrows (
428
+ funcTy->isThrowing (), thrownError));
429
+ }
430
+
407
431
FunctionType *ConstraintSystem::openFunctionType (
408
432
AnyFunctionType *funcType,
409
433
ConstraintLocatorBuilder locator,
@@ -419,7 +443,7 @@ FunctionType *ConstraintSystem::openFunctionType(
419
443
return openType (type, replacements, locator);
420
444
});
421
445
422
- funcType = genericFn-> substGenericArgs (
446
+ funcType = substGenericArgs (genericFn,
423
447
[&](Type type) { return openType (type, replacements, locator); });
424
448
}
425
449
@@ -1546,7 +1570,7 @@ DeclReferenceType ConstraintSystem::getTypeOfMemberReference(
1546
1570
openedType = value->getInterfaceType ()->castTo <AnyFunctionType>();
1547
1571
1548
1572
if (auto *genericFn = openedType->getAs <GenericFunctionType>()) {
1549
- openedType = genericFn-> substGenericArgs (
1573
+ openedType = substGenericArgs (genericFn,
1550
1574
[&](Type type) { return openType (type, replacements, locator); });
1551
1575
}
1552
1576
} else {
0 commit comments