Hi there,
Today, I realized that self
wasn't implicitly captured when it's within an "unowned" block as below.
func f1() {
runBlock { [unowned self] in
// self is safe here since runBlock won't run this block if not.
Task {
await slow() // self may be released while awaiting.
self.val = 0 // self is implicitly unowned; can trap!
}
}
}
Therefore I needed to fix this crash bug as below.
func f2() {
runBlock { [unowned self] in
Task { [self] in
await slow()
self.val = 0 // self is explicitly captured; no trap.
}
}
}
But I found it a bit surprising since the code below works fine.
func f3() {
runBlock {
Task {
await slow()
self.val = 0 // self is implicitly captured; no trap.
}
}
}
So, my question is, isn't this surprising or just me?