示例工程 22-swift6-strict-concurrency

22-swift6-strict-concurrency/Diagnostics/SendToActor.swift

swift · 0.3 KB

// 故意编译失败:把非 Sendable 值传给 actor 会转移所有权风险。
// 复现:swiftc -swift-version 6 Diagnostics/SendToActor.swift
final class Box {
    var value = 0
}
 
actor Store {
    func put(_ box: Box) {}
}
 
func run(_ store: Store) async {
    let box = Box()
    await store.put(box)
    box.value += 1
}