@@ -1259,7 +1259,8 @@ ClosureIsolatedByPreconcurrency::operator()(const ClosureExpr *expr) const {
1259
1259
1260
1260
Type ConstraintSystem::getUnopenedTypeOfReference (
1261
1261
VarDecl *value, Type baseType, DeclContext *UseDC,
1262
- ConstraintLocator *memberLocator, bool wantInterfaceType) {
1262
+ ConstraintLocator *memberLocator, bool wantInterfaceType,
1263
+ bool adjustForPreconcurrency) {
1263
1264
return ConstraintSystem::getUnopenedTypeOfReference (
1264
1265
value, baseType, UseDC,
1265
1266
[&](VarDecl *var) -> Type {
@@ -1272,22 +1273,25 @@ Type ConstraintSystem::getUnopenedTypeOfReference(
1272
1273
1273
1274
return wantInterfaceType ? var->getInterfaceType () : var->getType ();
1274
1275
},
1275
- memberLocator, wantInterfaceType, GetClosureType{*this },
1276
+ memberLocator, wantInterfaceType, adjustForPreconcurrency,
1277
+ GetClosureType{*this },
1276
1278
ClosureIsolatedByPreconcurrency{*this });
1277
1279
}
1278
1280
1279
1281
Type ConstraintSystem::getUnopenedTypeOfReference (
1280
1282
VarDecl *value, Type baseType, DeclContext *UseDC,
1281
1283
llvm::function_ref<Type(VarDecl *)> getType,
1282
- ConstraintLocator *memberLocator, bool wantInterfaceType,
1284
+ ConstraintLocator *memberLocator,
1285
+ bool wantInterfaceType, bool adjustForPreconcurrency,
1283
1286
llvm::function_ref<Type(const AbstractClosureExpr *)> getClosureType,
1284
1287
llvm::function_ref<bool(const ClosureExpr *)> isolatedByPreconcurrency) {
1285
1288
Type requestedType =
1286
1289
getType (value)->getWithoutSpecifierType ()->getReferenceStorageReferent ();
1287
1290
1288
- // Adjust the type for concurrency.
1289
- requestedType = adjustVarTypeForConcurrency (
1290
- requestedType, value, UseDC, getClosureType, isolatedByPreconcurrency);
1291
+ // Adjust the type for concurrency if requested.
1292
+ if (adjustForPreconcurrency)
1293
+ requestedType = adjustVarTypeForConcurrency (
1294
+ requestedType, value, UseDC, getClosureType, isolatedByPreconcurrency);
1291
1295
1292
1296
// If we're dealing with contextual types, and we referenced this type from
1293
1297
// a different context, map the type.
@@ -2309,9 +2313,14 @@ ConstraintSystem::getTypeOfMemberReference(
2309
2313
FunctionType::ExtInfo info;
2310
2314
refType = FunctionType::get (indices, elementTy, info);
2311
2315
} else {
2316
+ // Delay the adjustment for preconcurrency until after we've formed
2317
+ // the function type for this kind of reference. Otherwise we will lose
2318
+ // track of the adjustment in the formed function's return type.
2319
+
2312
2320
refType = getUnopenedTypeOfReference (cast<VarDecl>(value), baseTy, useDC,
2313
2321
locator,
2314
- /* wantInterfaceType=*/ true );
2322
+ /* wantInterfaceType=*/ true ,
2323
+ /* adjustForPreconcurrency=*/ false );
2315
2324
}
2316
2325
2317
2326
auto selfTy = outerDC->getSelfInterfaceType ();
@@ -2432,6 +2441,16 @@ ConstraintSystem::getTypeOfMemberReference(
2432
2441
openedType = adjustFunctionTypeForConcurrency (
2433
2442
origOpenedType->castTo <AnyFunctionType>(), subscript, useDC,
2434
2443
/* numApplies=*/ 2 , /* isMainDispatchQueue=*/ false , replacements);
2444
+ } else if (auto var = dyn_cast<VarDecl>(value)) {
2445
+ // Adjust the function's result type, since that's the Var's actual type.
2446
+ auto origFnType = origOpenedType->castTo <AnyFunctionType>();
2447
+
2448
+ auto resultTy = adjustVarTypeForConcurrency (
2449
+ origFnType->getResult (), var, useDC, GetClosureType{*this },
2450
+ ClosureIsolatedByPreconcurrency{*this });
2451
+
2452
+ openedType = FunctionType::get (
2453
+ origFnType->getParams (), resultTy, origFnType->getExtInfo ());
2435
2454
}
2436
2455
2437
2456
// Compute the type of the reference.
0 commit comments