Here is a code sample that I don't quite know how to interpret:
actor Test {
var x: Int = 0
func compiles() -> some Publisher {
return Just(1)
.handleEvents(receiveCompletion: { _ in
// Compiles ok
self.x += 1
})
}
func compiles2() -> some Publisher {
return Just(1)
.handleEvents(receiveCompletion: { [unowned self] _ in
// Compiles ok
self.x += 1
})
}
func doesnCompile() -> some Publisher {
return Just(1)
.handleEvents(receiveCompletion: { [weak self] _ in
// Actor-isolated property 'x' can not be mutated from a non-isolated context
self?.x += 1
})
}
func doesnCompile2() -> some Publisher {
return Just(1)
.handleEvents(receiveCompletion: { _ in
unowned var actor = self
// Actor-isolated property 'x' can not be mutated from a non-isolated context
actor.x += 1
})
}
}
The behaviour is the same in Minimal and Complete concurrency checking
I would have expected all of these examples to not compile. Is there some explanation for this behaviour?