[Concurrency] When expanding #isolation create a type-checked type

expr for global actors.

This eliminates a crash when type checking `#isolation` expansions
for global actors nested in other types, because the `TypeExpr`
does not properly represent the type repr for nested types. It's
simpler to provide the type directly instead of going through type
resolution.
This commit is contained in:
Holly Borla
2025-03-28 15:43:11 -07:00
parent a7b8cb79cd
commit 9c1f7e3ca5
2 changed files with 18 additions and 3 deletions

View File

@@ -4210,8 +4210,7 @@ namespace {
// Form a <global actor type>.shared reference.
Type globalActorType = getDeclContext()->mapTypeIntoContext(
isolation.getGlobalActor());
auto typeExpr = TypeExpr::createForDecl(
DeclNameLoc(loc), globalActorType->getAnyNominal(), dc);
auto typeExpr = TypeExpr::createImplicit(globalActorType, ctx);
actorExpr = new (ctx) UnresolvedDotExpr(
typeExpr, loc, DeclNameRef(ctx.Id_shared), DeclNameLoc(loc),
/*implicit=*/false);

View File

@@ -63,7 +63,7 @@ func mainActorIsolated() {
// CHECK-NEXT: inject_into_optional
// CHECK-NEXT: erasure_expr
// CHECK: member_ref_expr type="MainActor" location=@__swiftmacro_{{.*}} decl="_Concurrency.(file).MainActor.shared"
// CHECK-NEXT: type_expr type="MainActor.Type"
// CHECK-NEXT: type_expr implicit type="MainActor.Type"
_ = #isolation
}
@@ -126,3 +126,19 @@ func testContextualType() {
await concreteActorIsolation()
}
#endif
func isolationMacroDefault(
isolation: isolated (any Actor)? = #isolation,
) async -> Void {}
class C {
@globalActor
actor NestedActor {
static let shared = NestedActor()
}
@NestedActor
func expandIsolation() async {
await isolationMacroDefault()
}
}