Hello!
I’m testing Swift 6 (not Swift 5) on Xcode 26, and I don’t understand why the following code compiles without any errors, even though I’ve set the build setting
SWIFT_STRICT_CONCURRENCY = complete.
I was expecting a compiler error telling me that I’m accessing a variable outside the MainActor, which should not be allowed.
However, I get only a compiler warning but no error, and instead, the app crashes at runtime .
I have no crash with swift 5
Here’s the code:
class Test: ObservableObject {
let publisher = Publisher()
var bag = Set<AnyCancellable>()
init() {
publisher.value.sink {
print($0)
}.store(in: &bag)
}
}
@MainActor
class Publisher: @unchecked Sendable {
var value = PassthroughSubject<Int, Never>()
init() {
DispatchQueue.global().asyncAfter(deadline: .now() + 1) {
self.value.send(10)
}
}
}
It should not crash
and when I have this code I have a warning with crash
Main actor-isolated property 'publisher' can not be referenced from a Sendable closure
@MainActor
class Publisher: @unchecked Sendable {
var value = PassthroughSubject<Int, Never>()
init() {
DispatchQueue.global().asyncAfter(deadline: .now() + 1) {
self.value.send(10)
}
}
}
but this code no warning and no crash
@MainActor
class Publisher: @unchecked Sendable {
var value = PassthroughSubject<Int, Never>()
init() {
DispatchQueue.global().asyncAfter(deadline: .now() + 1) {
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
self.value.send(10)
}
}
}
}
in both case we have
self.value.send(10)
in
@preconcurrency public func asyncAfter(deadline: DispatchTime, qos: DispatchQoS = .unspecified, flags: DispatchWorkItemFlags = [], execute work: @escaping @Sendable @convention(block) () -> Void)
so we should have the same warning?

