jasonflax
(Jason Flax)
1
It seems in the latest version of 5.5, marking a function as Sendable only applies to value types and reference types declared as var. This compiles:
class Person {
var name = ""
}
func doStuff(_ block: (@Sendable () async throws -> Void)) async throws {
try await block()
}
func main() async throws {
let person = Person()
try await doStuff {
person.name = "Jon"
}
}
But I would assume it should not? Is this the intended behaviour or has this not been implemented yet?
ktoso
(Konrad 'ktoso' Malawski 🐟🏴☠️)
2
Hey there, this writeup should provide you most of the answers: Concurrency in Swift 5 and 6
Short version: we're on the road to Swift 6 which will enable all those checks and make them hard errors. In Swift 5.5 not everything is a hard error yet, but you can opt into more aggressive checking with optional compiler flags (e.g. -warn-concurrency enables Sendable checking).
Hope this helps!
1 Like