In proposal paper for the Swift language's actor model here, it's not allowed to call function returning non-Sendable type across actors.
However, I tried the example in the paper and it can compile and run while it suppose to emit errors.
class Person: CustomStringConvertible {
var name: String = ""
var description: String {
return "Person name: \(name)"
}
}
actor BankAccount {
var owners: [Person] = [Person()]
func primaryOwner() -> Person? {
return owners.first
}
}
@main
struct EntryPoint {
static func main() async {
let account = BankAccount()
if let owner = await account.primaryOwner() {
owner.name = "FooBar" // Change actor's mutable state outside of actor-isolated context
}
print(await account.owners)
}
}
// Output: [Person name: FooBar]
My Swift version
$ swift --version
Swift version 5.5.1 (swift-5.5.1-RELEASE)
Target: x86_64-unknown-linux-gnu
Did I do something wrong in the code above? If I did it right, why the implementation does not conform with the proposal paper?
Thanks.