@@ -404,6 +404,30 @@ Type ConstraintSystem::openOpaqueType(Type type, ContextualTypePurpose context,
404404 });
405405}
406406
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+
407431FunctionType *ConstraintSystem::openFunctionType (
408432 AnyFunctionType *funcType,
409433 ConstraintLocatorBuilder locator,
@@ -419,7 +443,7 @@ FunctionType *ConstraintSystem::openFunctionType(
419443 return openType (type, replacements, locator);
420444 });
421445
422- funcType = genericFn-> substGenericArgs (
446+ funcType = substGenericArgs (genericFn,
423447 [&](Type type) { return openType (type, replacements, locator); });
424448 }
425449
@@ -1546,7 +1570,7 @@ DeclReferenceType ConstraintSystem::getTypeOfMemberReference(
15461570 openedType = value->getInterfaceType ()->castTo <AnyFunctionType>();
15471571
15481572 if (auto *genericFn = openedType->getAs <GenericFunctionType>()) {
1549- openedType = genericFn-> substGenericArgs (
1573+ openedType = substGenericArgs (genericFn,
15501574 [&](Type type) { return openType (type, replacements, locator); });
15511575 }
15521576 } else {
0 commit comments