I flipped Swift 6 on and I'm getting the following error, which I'm pretty sure is incorrect, since the type in question is Sendable. What should I do?
// Sending main actor-isolated 'toast' to actor-isolated instance method 'eat(toast:)' risks causing data races between actor-isolated and main actor-isolated uses
struct Toast: Sendable {}
actor Person {
func eat(toast: Toast) {}
}
@MainActor
final class Toaster {
func makeToast() -> Toast {
Toast()
}
}
@MainActor
func test() async {
let person = Person()
let toaster = Toaster()
let toast = toaster.makeToast()
// // If I use var, there is no error.
// var toast = toaster.makeToast()
// Sending main actor-isolated 'toast' to actor-isolated instance method 'eat(toast:)' risks causing data races between actor-isolated and main actor-isolated uses
//
// 😕...Toast is a Sendable type, how could sending it anywhere risk causing data races?
// If I create Toast right here directly, there is no error:
// let toast = Toast()
await person.eat(toast: toast)
}