Skip to content

Commit 7de7eaf

Browse files
committed
[Concurrency] Don't walk into sending closures when computing the
required isolation of a default value expression.
1 parent dad0027 commit 7de7eaf

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2703,7 +2703,8 @@ namespace {
27032703
// function type, but this is okay for non-Sendable closures
27042704
// because they cannot leave the isolation domain they're created
27052705
// in anyway.
2706-
if (closure->isSendable())
2706+
if (isIsolationInferenceBoundaryClosure(
2707+
closure, /*can inherit actor context*/false))
27072708
return false;
27082709

27092710
if (closure->getActorIsolation().isActorIsolated())

test/Concurrency/isolated_default_arguments.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,18 @@ class C3 {
214214
@SomeGlobalActor var y = 2
215215
}
216216

217+
class C4 {
218+
let task1 = Task {
219+
// expected-error@+2 {{expression is 'async' but is not marked with 'await'}}
220+
// expected-note@+1 {{calls to global function 'requiresMainActor()' from outside of its actor context are implicitly asynchronous}}
221+
requiresMainActor()
222+
}
223+
224+
let task2 = Task {
225+
await requiresMainActor() // okay
226+
}
227+
}
228+
217229
@MainActor struct NonIsolatedInit {
218230
var x = 0
219231
var y = 0

test/Concurrency/isolated_default_property_inits.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
// REQUIRES: concurrency
99
// REQUIRES: asserts
1010

11+
// This tests errors emitted in definite initialization; this test file cannot
12+
// have any type checker errors. Type checker errors for IsolatedDefaultValues
13+
// are tested in isolated_default_arguments.swift
14+
1115
@globalActor
1216
actor SomeGlobalActor {
1317
static let shared = SomeGlobalActor()

0 commit comments

Comments
 (0)