A concurrency pothole I just fell into

I don't know if there is supposed to be perfect parity between the warnings with the StrictConcurrency flag in Swift 5 mode and the errors in Swift 6 mode, but here is a difference between them I just found:

func test() async {
    let notSendable =
        await {
            let myActor = MyActor(notSendable: .init())
            await myActor.notSendable.increment()
            return await myActor.notSendable
        }()
    
    let myActor = MyActor(notSendable: notSendable)
}
final actor MyActor {
    let notSendable: NotSendable
    
    init(notSendable: NotSendable) {
        self.notSendable = notSendable
        
        Task {
            await self.increment()
        }
    }
    
    func increment() {
        notSendable.increment()
    }
}
final class NotSendable {
    var foo: Int = 0
    func increment() {
        foo += 1
    }
}

In Swift 5 with strict concurrency there are no warnings, but in Swift 6 the await myActor.notSendable.increment() and the return await myActor.notSendable both raise the error:

Non-sendable type 'NotSendable' in implicitly asynchronous access to actor-isolated property 'notSendable' cannot cross actor boundary

Is there supposed to be a warning in Swift 5 with strict concurrency?

1 Like

I have warnings all over in Swift 5 mode with strict checks turned on:

warning: non-sendable type 'NotSendable' in implicitly asynchronous access to actor-isolated property 'notSendable' cannot cross actor boundary; this is an error in the Swift 6 language mode