Swift 6 (from Xcode 16b5), overridden function and isolation

Has the isolation of override functions been changed with the latest beta release? The following two code snippets produce 1 failure to compile and 2 warnings. Earlier beta's had no issue with either snippet:

import Foundation
import UIKit

@MainActor class TestObject: NSObject {
    
    let testView = UIView(frame: .zero)
    
    private func doSomething() {
        
    }
    
    override init() {
        // [ERROR] Property 'self.testView' not initialised at super.init call 

        super.init()    
        
         // [WARNING] Call to main actor-isolated instance method 'doSomething()' in a synchronous nonisolated context; this is an error in the Swift 6 language mode

        doSomething()
    }
}

and

import Foundation
import UIKit

class TestListCell: UICollectionViewCell {
    
    private func doSomething() {
        
    }
    
    override func awakeFromNib() {

        // [WARNING] Call to main actor-isolated instance method 'doSomething()' in a synchronous nonisolated context; this is an error in the Swift 6 language mode

        doSomething()
    }    
}

(Compiling with complete concurrency checking but with the swift language mode set to 5)

Currently the simples solution to roll back to beta 4 and wait for 6th:

2 Likes

To be clear, my fix is only for subclassing NSObject.init() because to experience a data race, you'd need to call the subclass override dynamically through an NSObject metatype, which I think is rare (or impossible?). It is correct to get an error when trying to override a nonisolated superclass method in a subclass that adds actor isolation, and that was already the case for this pattern written purely in Swift. If you believe that a superclass method from an Apple framework you're using is missing an annotation like @MainActor, please report the issue via Apple Feedback Assistant.

2 Likes