@@ -1397,9 +1397,11 @@ static ManagedValue emitBuiltinCreateAsyncTaskFuture(
1397
1397
1398
1398
// Form the metatype of the result type.
1399
1399
CanType futureResultType =
1400
- Type (
1401
- MetatypeType::get (GenericTypeParamType::get (0 , 0 , SGF.getASTContext ()), MetatypeRepresentation::Thick))
1402
- .subst (subs)->getCanonicalType ();
1400
+ Type (MetatypeType::get (
1401
+ GenericTypeParamType::get (0 , 0 , SGF.getASTContext ()),
1402
+ MetatypeRepresentation::Thick))
1403
+ .subst (subs)
1404
+ ->getCanonicalType ();
1403
1405
CanType anyTypeType = ExistentialMetatypeType::get (
1404
1406
ProtocolCompositionType::get (ctx, { }, false ))->getCanonicalType ();
1405
1407
auto &anyTypeTL = SGF.getTypeLowering (anyTypeType);
@@ -1411,8 +1413,27 @@ static ManagedValue emitBuiltinCreateAsyncTaskFuture(
1411
1413
SGF.B .createMetatype (loc, SGF.getLoweredType (futureResultType)));
1412
1414
}).borrow (SGF, loc).forward (SGF);
1413
1415
1414
- auto function = emitFunctionArgumentForAsyncTaskEntryPoint (SGF, loc, args[2 ],
1415
- futureResultType);
1416
+ // Ensure that the closure has the appropriate type.
1417
+ auto extInfo =
1418
+ ASTExtInfoBuilder ()
1419
+ .withAsync ()
1420
+ .withThrows ()
1421
+ .withRepresentation (GenericFunctionType::Representation::Swift)
1422
+ .build ();
1423
+ auto genericSig = subs.getGenericSignature ().getCanonicalSignature ();
1424
+ auto genericResult = GenericTypeParamType::get (0 , 0 , ctx);
1425
+ // <T> () async throws -> T
1426
+ CanType functionTy =
1427
+ GenericFunctionType::get (genericSig, {}, genericResult, extInfo)
1428
+ ->getCanonicalType ();
1429
+ AbstractionPattern origParam (genericSig, functionTy);
1430
+ CanType substParamType = functionTy.subst (subs)->getCanonicalType ();
1431
+ auto reabstractedFun =
1432
+ SGF.emitSubstToOrigValue (loc, args[2 ], origParam, substParamType);
1433
+
1434
+ auto function = emitFunctionArgumentForAsyncTaskEntryPoint (
1435
+ SGF, loc, reabstractedFun, futureResultType);
1436
+
1416
1437
auto apply = SGF.B .createBuiltin (
1417
1438
loc,
1418
1439
ctx.getIdentifier (
0 commit comments