Just a little confused by this. In the given example, I expect prop1 to have a await but I'm surprised the compiler does not want a await for prop2? I was expecting there to be a await in both prop1 and prop2? Initially, I thought they would have been equivalent?
import Foundation
@globalActor actor MySpecialActor {
static let shared = MySpecialActor()
}
final class TestProperties: Sendable {
@MySpecialActor var prop1: Int {
42
}
var prop2: Int {
@MySpecialActor get {
64
}
}
var prop3: Int {
@MySpecialActor get {
self.blabla() // ok, no await as expected
}
}
@MySpecialActor private func blabla() -> Int {
128
}
}
let t = TestProperties()
let value = await t.prop1 // Requires await
let value2 = t.prop2 // Does not require await?
let value3 = t.prop3 // Does not require await?
For kicks, if I modify the example, then the playground (Xcode 16.0 16A242d) shows an error:
Pattern that the region based isolation checker does not understand how to check. Please file a bug.
I wanted to introduce a variable to the example. Needed to modify to get around Sendable. Perhaps, this is related to the prior post.
import Foundation
@globalActor actor MySpecialActor {
static let shared = MySpecialActor()
}
final class TestProperties {
var prop2: Int {
@MySpecialActor get { 64 }
}
var prop3: Int {
@MySpecialActor get {
self.blabla() // ok, no await as expected
}
}
var test = 465
@MySpecialActor private func blabla() -> Int {
test
}
}
let t = TestProperties()
Task {
let value5 = t.prop2 // Does not require await?
let value6 = t.prop3 // Does not require await?
}
Just some context, I am trying to migrate some code to Swift Concurrency. I removed a NSLock and the await propagates up the call chain into a computed property. Code posted here is from a playground.