With this setup:
@preconcurrency import AVFoundation
actor A {
func getSession() -> AVCaptureSession { nonoptionalSession }
let nonoptionalSession: AVCaptureSession
let optionalSession: AVCaptureSession!
func getLayer() -> AVCaptureVideoPreviewLayer { nonoptionalLayer }
let nonoptionalLayer: AVCaptureVideoPreviewLayer
let optionalLayer: AVCaptureVideoPreviewLayer!
init() { fatalError() }
}
nonisolated class C {}
I am getting expected warnings about lack of sendability here:
extension C {
func test1(a: A) async {
_ = await a.getLayer() // sendability warning (expected)
_ = await a.nonoptionalLayer // sendability warning (expected)
}
}
(expected as if I change @preconcurrency import to normal import the warnings are changed to errors)
unexpected lack of sendability warnings here:
extension C {
func test2(a: A) async {
_ = await a.getSession() // no sendability warning
_ = await a.nonoptionalSession // no sendability warning
_ = await a.optionalSession! // no sendability warning
}
}
and somewhat unexpected error here (unexpected because similar code compiles without an error in test2):
extension C {
func test3(a: A) async {
// uncomment to see the error
// _ = await a.optionalLayer! // sendability error
}
}
I guess Swift itself is in the clear here, and there's just some difference (in api notes?) for AVCaptureVideoPreviewLayer and AVCaptureSession that'd explain this observable disparity?