@@ -286,6 +286,27 @@ static Type getIdentityOpaqueTypeArchetypeType(
286
286
return OpaqueTypeArchetypeType::get (opaqueDecl, interfaceType, subs);
287
287
}
288
288
289
+ // / Adjust the underlying type of a typealias within the given context to
290
+ // / account for @preconcurrency.
291
+ static Type adjustTypeAliasTypeInContext (
292
+ Type type, TypeAliasDecl *aliasDecl, DeclContext *fromDC) {
293
+ if (!aliasDecl->preconcurrency ())
294
+ return type;
295
+
296
+ if (contextRequiresStrictConcurrencyChecking (
297
+ fromDC,
298
+ [](const AbstractClosureExpr *closure) {
299
+ return closure->getType ();
300
+ },
301
+ [](const ClosureExpr *closure) {
302
+ return closure->isIsolatedByPreconcurrency ();
303
+ }))
304
+ return type;
305
+
306
+ return type->stripConcurrency (
307
+ /* recurse=*/ true , /* dropGlobalActor=*/ true );
308
+ }
309
+
289
310
Type TypeResolution::resolveTypeInContext (TypeDecl *typeDecl,
290
311
DeclContext *foundDC,
291
312
bool isSpecialized) const {
@@ -307,6 +328,13 @@ Type TypeResolution::resolveTypeInContext(TypeDecl *typeDecl,
307
328
return genericParam->getDeclaredInterfaceType ();
308
329
}
309
330
331
+ // / Call this function before returning the underlying type of a typealias,
332
+ // / to adjust its type for concurrency.
333
+ auto adjustAliasType = [&](Type type) -> Type {
334
+ return adjustTypeAliasTypeInContext (
335
+ type, cast<TypeAliasDecl>(typeDecl), fromDC);
336
+ };
337
+
310
338
if (!isSpecialized) {
311
339
// If we are referring to a type within its own context, and we have either
312
340
// a generic type with no generic arguments or a non-generic type, use the
@@ -342,9 +370,9 @@ Type TypeResolution::resolveTypeInContext(TypeDecl *typeDecl,
342
370
if (ugAliasDecl == aliasDecl) {
343
371
if (getStage () == TypeResolutionStage::Structural &&
344
372
aliasDecl->getUnderlyingTypeRepr () != nullptr ) {
345
- return aliasDecl->getStructuralType ();
373
+ return adjustAliasType ( aliasDecl->getStructuralType () );
346
374
}
347
- return aliasDecl->getDeclaredInterfaceType ();
375
+ return adjustAliasType ( aliasDecl->getDeclaredInterfaceType () );
348
376
}
349
377
350
378
extendedType = unboundGeneric->getParent ();
@@ -356,9 +384,9 @@ Type TypeResolution::resolveTypeInContext(TypeDecl *typeDecl,
356
384
if (aliasType->getDecl () == aliasDecl) {
357
385
if (getStage () == TypeResolutionStage::Structural &&
358
386
aliasDecl->getUnderlyingTypeRepr () != nullptr ) {
359
- return aliasDecl->getStructuralType ();
387
+ return adjustAliasType ( aliasDecl->getStructuralType () );
360
388
}
361
- return aliasDecl->getDeclaredInterfaceType ();
389
+ return adjustAliasType ( aliasDecl->getDeclaredInterfaceType () );
362
390
}
363
391
extendedType = aliasType->getParent ();
364
392
continue ;
@@ -381,9 +409,9 @@ Type TypeResolution::resolveTypeInContext(TypeDecl *typeDecl,
381
409
// Otherwise, return the appropriate type.
382
410
if (getStage () == TypeResolutionStage::Structural &&
383
411
aliasDecl->getUnderlyingTypeRepr () != nullptr ) {
384
- return aliasDecl->getStructuralType ();
412
+ return adjustAliasType ( aliasDecl->getStructuralType () );
385
413
}
386
- return aliasDecl->getDeclaredInterfaceType ();
414
+ return adjustAliasType ( aliasDecl->getDeclaredInterfaceType () );
387
415
}
388
416
389
417
// When a nominal type used outside its context, return the unbound
@@ -1571,6 +1599,12 @@ static Type resolveNestedIdentTypeComponent(TypeResolution resolution,
1571
1599
AssociatedTypeDecl *inferredAssocType) {
1572
1600
bool hasUnboundOpener = !!resolution.getUnboundTypeOpener ();
1573
1601
1602
+ // Type aliases might require adjustment due to @preconcurrency.
1603
+ if (auto aliasDecl = dyn_cast<TypeAliasDecl>(member)) {
1604
+ memberType = adjustTypeAliasTypeInContext (
1605
+ memberType, aliasDecl, resolution.getDeclContext ());
1606
+ }
1607
+
1574
1608
if (options.contains (TypeResolutionFlags::SilenceErrors)) {
1575
1609
if (TypeChecker::isUnsupportedMemberTypeAccess (parentTy, member,
1576
1610
hasUnboundOpener)
@@ -4401,6 +4435,7 @@ class ExistentialTypeVisitor
4401
4435
}
4402
4436
} else if (auto *alias = dyn_cast_or_null<TypeAliasDecl>(comp->getBoundDecl ())) {
4403
4437
auto type = Type (alias->getDeclaredInterfaceType ()->getDesugaredType ());
4438
+
4404
4439
// If this is a type alias to a constraint type, the type
4405
4440
// alias name must be prefixed with 'any' to be used as an
4406
4441
// existential type.
0 commit comments