Skip to content

Commit 9c1f7e3

Browse files
committed
[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.
1 parent a7b8cb7 commit 9c1f7e3

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4210,8 +4210,7 @@ namespace {
42104210
// Form a <global actor type>.shared reference.
42114211
Type globalActorType = getDeclContext()->mapTypeIntoContext(
42124212
isolation.getGlobalActor());
4213-
auto typeExpr = TypeExpr::createForDecl(
4214-
DeclNameLoc(loc), globalActorType->getAnyNominal(), dc);
4213+
auto typeExpr = TypeExpr::createImplicit(globalActorType, ctx);
42154214
actorExpr = new (ctx) UnresolvedDotExpr(
42164215
typeExpr, loc, DeclNameRef(ctx.Id_shared), DeclNameLoc(loc),
42174216
/*implicit=*/false);

test/Concurrency/isolation_macro.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func mainActorIsolated() {
6363
// CHECK-NEXT: inject_into_optional
6464
// CHECK-NEXT: erasure_expr
6565
// CHECK: member_ref_expr type="MainActor" location=@__swiftmacro_{{.*}} decl="_Concurrency.(file).MainActor.shared"
66-
// CHECK-NEXT: type_expr type="MainActor.Type"
66+
// CHECK-NEXT: type_expr implicit type="MainActor.Type"
6767
_ = #isolation
6868
}
6969

@@ -126,3 +126,19 @@ func testContextualType() {
126126
await concreteActorIsolation()
127127
}
128128
#endif
129+
130+
func isolationMacroDefault(
131+
isolation: isolated (any Actor)? = #isolation,
132+
) async -> Void {}
133+
134+
class C {
135+
@globalActor
136+
actor NestedActor {
137+
static let shared = NestedActor()
138+
}
139+
140+
@NestedActor
141+
func expandIsolation() async {
142+
await isolationMacroDefault()
143+
}
144+
}

0 commit comments

Comments
 (0)