Skip to content

Commit a8a55eb

Browse files
committed
[Concurrency] Look through caller-side default arguments for #isolation
when computing the isolated actor expression for a call.
1 parent a24fe7c commit a8a55eb

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3378,6 +3378,12 @@ namespace {
33783378

33793379
// FIXME: CurrentContextIsolationExpr does not have its actor set
33803380
// at this point.
3381+
if (auto *defaultArg = dyn_cast<DefaultArgumentExpr>(arg)) {
3382+
// Look through caller-side default arguments for #isolation.
3383+
if (defaultArg->isCallerSide()) {
3384+
arg = defaultArg->getCallerSideDefaultExpr();
3385+
}
3386+
}
33813387
if (auto *macro = dyn_cast<MacroExpansionExpr>(arg)) {
33823388
auto *expansion = macro->getRewritten();
33833389
if (auto *isolation = dyn_cast<CurrentContextIsolationExpr>(expansion)) {

test/Concurrency/isolated_parameters.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,3 +477,11 @@ nonisolated func fromNonisolated(ns: NotSendable) async -> NotSendable {
477477
func invalidIsolatedClosureParam<A: AnyActor> (
478478
_: (isolated A) async throws -> Void // expected-error {{'isolated' parameter type 'A' does not conform to 'Actor' or 'DistributedActor'}}
479479
) {}
480+
481+
public func useDefaultIsolation(
482+
_ isolation: isolated (any Actor)? = #isolation
483+
) {}
484+
485+
@MainActor func callUseDefaultIsolation() async {
486+
useDefaultIsolation()
487+
}

0 commit comments

Comments
 (0)