No sendability warning for `Task` with strict concurrency check = targeted

Hello!

We are using swift concurrency with Strict Concurrency Checking = Targeted.
The problem is that there is no non-Sendable warnings for async code in Task closures:

StringCollector isn't Sendable in this case and will crash at array.append. In my understanding the code inside the closure should be considered as concurrent and sendability check should be performed.

With Complete level the warning will show up as expected:

Is it a bug? Or maybe we can somehow enforce sendability checks with Targeted level for tasks?

Code
final class ViewModel {
    let stringsCollector = StringsCollector()

    func collectStrings() {
        for _ in 0...1000 {
            Task { [stringsCollector] in
                await stringsCollector.addStringToArray()
            }
        }
    }
}

final class StringsCollector {
    var array = [String]()

    func addStringToArray() async {
        array.append("string")
    }
}

Relevant reading:

You may be better served by opting into specific upcoming features than trying to use targeted mode.

Yeah at this point really targeted isn't something that should be used -- aim to use complete checking as that's what actually will give you the swift 6 mode and "correct" semantics moving forward.

2 Likes

I like the idea, but only the last 2 of 4 upcoming features in this thread provide checks, and for very specific cases. So I don't see it as a replacement for the targeted checking right now, unfortunately.

We are in the same situation as was described in this comment on the thread above: a really large codebase. We want to start using concurrency, but complete level brings too many changes. So targeted level sounds like a great option for us since it helps to write new correct concurrent code without touching the old.