Considering below dummy codes:
@MainActor var globalNumber = 0
@MainActor
func increase(_ number: inout Int) async {
// some async code excluded
number += 1
}
class Dummy: @unchecked Sendable {
@MainActor var number: Int {
get { globalNumber }
set { globalNumber = newValue }
}
@MainActor
func change() async {
await increase(&number) //Actor-isolated property 'number' cannot be passed 'inout' to 'async' function call
}
}
I'm not really trying to make an increasing function like that, this is just an example to make everything happen. As for why number
is a computed property, this is to trigger the actor-isolated
condition (otherwise, if the property is stored and is a value type, this condition will not be triggered).
Under these conditions, in function change()
, I got the error: Actor-isolated property 'number' cannot be passed 'inout' to 'async' function call
.
My question is: Why Actor-isolated property cannot be passed 'inout' to 'async' function call? What is the purpose of this design? If this were allowed, what problems might it cause?