Avatar
Avatar
Yuta Saito
@swift-main -strict-concurrency=complete import Foundation func takeSendableClosure(_ c: @Sendable @escaping () -> ()) { Task.detached(operation: c) } let nonSendable: () -> () = {} takeSendableClosure(nonSendable) // 警告出る struct S { var nonSendableValue: () -> () @Sendable func mayUseNonSendableValue() { nonSendableValue() } } var count = 0 var s = S(nonSendableValue: { count += 1 }) takeSendableClosure(s.mayUseNonSendableValue) // 警告出ない for _ in 0..<10000 { takeSendableClosure(s.mayUseNonSendableValue) } print(count) sleep(1) print(count)
swiftNightly BOT 11/6/2023 3:14 AM
9798 9977<stdin>:7:21: warning: converting non-sendable function value to '@Sendable () -> ()' may introduce data races takeSendableClosure(nonSendable) // 警告出る <stdin>:11:3: warning: instance methods of non-Sendable types cannot be marked as '@Sendable'; this is an error in Swift 6 @Sendable func mayUseNonSendableValue() { ^