Should global-actor-isolated functions be implicitly Sendable?

I was surprised today to find that the following code produces a warning:

@MainActor class C {
    var x: Int = 0
    func inc() {
        x += 1
    }
}

@MainActor
func g() async {
    @MainActor
    func f() async {} // warning: concurrently-executed local function 'f()' must be marked as '@Sendable'; this is an error in Swift 6

    let c: C = C()

    Task.detached {
        await f()
        await c.inc()
    }
}

The warning is fixed by marking f as @Sendable, but should we have to do that? The call to c.inc() succeeds fine due to this rule from SE-0316:

A non-protocol type that is annotated with a global actor implicitly conforms to Sendable .

I don't recall whether this came up in the midst of the concurrency proposals, but is there any reason this courtesy isn't extended to functions?

3 Likes