@@ -286,6 +286,27 @@ static Type getIdentityOpaqueTypeArchetypeType(
286286 return OpaqueTypeArchetypeType::get (opaqueDecl, interfaceType, subs);
287287}
288288
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+
289310Type TypeResolution::resolveTypeInContext (TypeDecl *typeDecl,
290311 DeclContext *foundDC,
291312 bool isSpecialized) const {
@@ -307,6 +328,13 @@ Type TypeResolution::resolveTypeInContext(TypeDecl *typeDecl,
307328 return genericParam->getDeclaredInterfaceType ();
308329 }
309330
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+
310338 if (!isSpecialized) {
311339 // If we are referring to a type within its own context, and we have either
312340 // a generic type with no generic arguments or a non-generic type, use the
@@ -342,9 +370,9 @@ Type TypeResolution::resolveTypeInContext(TypeDecl *typeDecl,
342370 if (ugAliasDecl == aliasDecl) {
343371 if (getStage () == TypeResolutionStage::Structural &&
344372 aliasDecl->getUnderlyingTypeRepr () != nullptr ) {
345- return aliasDecl->getStructuralType ();
373+ return adjustAliasType ( aliasDecl->getStructuralType () );
346374 }
347- return aliasDecl->getDeclaredInterfaceType ();
375+ return adjustAliasType ( aliasDecl->getDeclaredInterfaceType () );
348376 }
349377
350378 extendedType = unboundGeneric->getParent ();
@@ -356,9 +384,9 @@ Type TypeResolution::resolveTypeInContext(TypeDecl *typeDecl,
356384 if (aliasType->getDecl () == aliasDecl) {
357385 if (getStage () == TypeResolutionStage::Structural &&
358386 aliasDecl->getUnderlyingTypeRepr () != nullptr ) {
359- return aliasDecl->getStructuralType ();
387+ return adjustAliasType ( aliasDecl->getStructuralType () );
360388 }
361- return aliasDecl->getDeclaredInterfaceType ();
389+ return adjustAliasType ( aliasDecl->getDeclaredInterfaceType () );
362390 }
363391 extendedType = aliasType->getParent ();
364392 continue ;
@@ -381,9 +409,9 @@ Type TypeResolution::resolveTypeInContext(TypeDecl *typeDecl,
381409 // Otherwise, return the appropriate type.
382410 if (getStage () == TypeResolutionStage::Structural &&
383411 aliasDecl->getUnderlyingTypeRepr () != nullptr ) {
384- return aliasDecl->getStructuralType ();
412+ return adjustAliasType ( aliasDecl->getStructuralType () );
385413 }
386- return aliasDecl->getDeclaredInterfaceType ();
414+ return adjustAliasType ( aliasDecl->getDeclaredInterfaceType () );
387415 }
388416
389417 // When a nominal type used outside its context, return the unbound
@@ -1591,6 +1619,12 @@ static Type resolveNestedIdentTypeComponent(TypeResolution resolution,
15911619 AssociatedTypeDecl *inferredAssocType) {
15921620 bool hasUnboundOpener = !!resolution.getUnboundTypeOpener ();
15931621
1622+ // Type aliases might require adjustment due to @preconcurrency.
1623+ if (auto aliasDecl = dyn_cast<TypeAliasDecl>(member)) {
1624+ memberType = adjustTypeAliasTypeInContext (
1625+ memberType, aliasDecl, resolution.getDeclContext ());
1626+ }
1627+
15941628 if (options.contains (TypeResolutionFlags::SilenceErrors)) {
15951629 if (TypeChecker::isUnsupportedMemberTypeAccess (parentTy, member,
15961630 hasUnboundOpener)
@@ -4493,6 +4527,7 @@ class ExistentialTypeVisitor
44934527 }
44944528 } else if (auto *alias = dyn_cast_or_null<TypeAliasDecl>(comp->getBoundDecl ())) {
44954529 auto type = Type (alias->getDeclaredInterfaceType ()->getDesugaredType ());
4530+
44964531 // If this is a type alias to a constraint type, the type
44974532 // alias name must be prefixed with 'any' to be used as an
44984533 // existential type.
0 commit comments