@@ -1210,7 +1210,8 @@ ClosureIsolatedByPreconcurrency::operator()(const ClosureExpr *expr) const {
1210
1210
1211
1211
Type ConstraintSystem::getUnopenedTypeOfReference (
1212
1212
VarDecl *value, Type baseType, DeclContext *UseDC,
1213
- ConstraintLocator *memberLocator, bool wantInterfaceType) {
1213
+ ConstraintLocator *memberLocator, bool wantInterfaceType,
1214
+ bool adjustForPreconcurrency) {
1214
1215
return ConstraintSystem::getUnopenedTypeOfReference (
1215
1216
value, baseType, UseDC,
1216
1217
[&](VarDecl *var) -> Type {
@@ -1223,22 +1224,25 @@ Type ConstraintSystem::getUnopenedTypeOfReference(
1223
1224
1224
1225
return wantInterfaceType ? var->getInterfaceType () : var->getType ();
1225
1226
},
1226
- memberLocator, wantInterfaceType, GetClosureType{*this },
1227
+ memberLocator, wantInterfaceType, adjustForPreconcurrency,
1228
+ GetClosureType{*this },
1227
1229
ClosureIsolatedByPreconcurrency{*this });
1228
1230
}
1229
1231
1230
1232
Type ConstraintSystem::getUnopenedTypeOfReference (
1231
1233
VarDecl *value, Type baseType, DeclContext *UseDC,
1232
1234
llvm::function_ref<Type(VarDecl *)> getType,
1233
- ConstraintLocator *memberLocator, bool wantInterfaceType,
1235
+ ConstraintLocator *memberLocator,
1236
+ bool wantInterfaceType, bool adjustForPreconcurrency,
1234
1237
llvm::function_ref<Type(const AbstractClosureExpr *)> getClosureType,
1235
1238
llvm::function_ref<bool(const ClosureExpr *)> isolatedByPreconcurrency) {
1236
1239
Type requestedType =
1237
1240
getType (value)->getWithoutSpecifierType ()->getReferenceStorageReferent ();
1238
1241
1239
- // Adjust the type for concurrency.
1240
- requestedType = adjustVarTypeForConcurrency (
1241
- requestedType, value, UseDC, getClosureType, isolatedByPreconcurrency);
1242
+ // Adjust the type for concurrency if requested.
1243
+ if (adjustForPreconcurrency)
1244
+ requestedType = adjustVarTypeForConcurrency (
1245
+ requestedType, value, UseDC, getClosureType, isolatedByPreconcurrency);
1242
1246
1243
1247
// If we're dealing with contextual types, and we referenced this type from
1244
1248
// a different context, map the type.
@@ -2260,9 +2264,14 @@ ConstraintSystem::getTypeOfMemberReference(
2260
2264
FunctionType::ExtInfo info;
2261
2265
refType = FunctionType::get (indices, elementTy, info);
2262
2266
} else {
2267
+ // Delay the adjustment for preconcurrency until after we've formed
2268
+ // the function type for this kind of reference. Otherwise we will lose
2269
+ // track of the adjustment in the formed function's return type.
2270
+
2263
2271
refType = getUnopenedTypeOfReference (cast<VarDecl>(value), baseTy, useDC,
2264
2272
locator,
2265
- /* wantInterfaceType=*/ true );
2273
+ /* wantInterfaceType=*/ true ,
2274
+ /* adjustForPreconcurrency=*/ false );
2266
2275
}
2267
2276
2268
2277
auto selfTy = outerDC->getSelfInterfaceType ();
@@ -2383,6 +2392,16 @@ ConstraintSystem::getTypeOfMemberReference(
2383
2392
openedType = adjustFunctionTypeForConcurrency (
2384
2393
origOpenedType->castTo <AnyFunctionType>(), subscript, useDC,
2385
2394
/* numApplies=*/ 2 , /* isMainDispatchQueue=*/ false , replacements);
2395
+ } else if (auto var = dyn_cast<VarDecl>(value)) {
2396
+ // Adjust the function's result type, since that's the Var's actual type.
2397
+ auto origFnType = origOpenedType->castTo <AnyFunctionType>();
2398
+
2399
+ auto resultTy = adjustVarTypeForConcurrency (
2400
+ origFnType->getResult (), var, useDC, GetClosureType{*this },
2401
+ ClosureIsolatedByPreconcurrency{*this });
2402
+
2403
+ openedType = FunctionType::get (
2404
+ origFnType->getParams (), resultTy, origFnType->getExtInfo ());
2386
2405
}
2387
2406
2388
2407
// Compute the type of the reference.
0 commit comments