Skip to content

[Concurrency] When expanding #isolation create a type-checked type expr for global actors. #80382

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/Sema/TypeCheckConcurrency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 17 additions & 1 deletion test/Concurrency/isolation_macro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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()
}
}