Accessing main actor-isolated property from deinit is allowed, but should it?

To my surprise I'm allowed to access Main actor-isolated property from a non isolated context in one case (but not another). What's the rationale here, or is it a WIP, not fully implemented feature?

@MainActor class C {
    var x = [1:2]
}

@MainActor class D: C {
    var y = [1:2]
    
    deinit {
        print(y[1]) // ok?!
        print(x[1]) // expected error: Main actor-isolated property 'x' can not be referenced from a nonisolated context
    }
}

await MainActor.run {
    var c: C? = C()
    DispatchQueue.global().async {
        c = nil
    }
}
RunLoop.main.run(until: Date.distantFuture)

I see the error when building in Swift 6 mode.

1 Like

Not getting any error in Swift 6 (either Xcode 16.4 or 16.1) in this minimal sample:

@MainActor class C {
    var x = [1:2]
}

@MainActor class D: C {
    var y = [1:2]
    
    deinit {
        print(y[1]) // ok?!
        //print(x[1]) // Error: Main actor-isolated property 'x' can not be referenced from a nonisolated context
    }
}

Oh, you mean a diagnostic for y. I'm not sure. No diagnostic in Swift 6.2 either, and you can get the access of x to work by making it an isolated deinit.