Cannot access property with a non-sendable type from non-isolated deinit

Interestingly, when self is accessed inside deinit, my previous successful code started to show warning:

actor Foo {
    // I want to clean up this array on `deinit`...
    var array: [String] = []

    func removeAll() {
        array.removeAll()
    }

    deinit {
        print(self) // Accessing `self`...

        // Accessing `self` will start showing:
        // WARNING: Cannot access property 'array' here in deinitializer; this is an error in Swift 6
        array.removeAll()

        // WARNING: Actor-isolated instance method 'removeAll()' can not be referenced from a non-isolated context; this is an error in Swift 6
        // self.removeAll()
    }
}

I think this warning difference is due to some subtle compiler bug.

And since actor-deinit is non-isolated now, and array.removeAll() is same as self.array.removeAll() which accesses self, I believe "always" showing warning is the correct compiler behavior (which of course is still annoying).

2 Likes