Swift 5.7 compiler doesn't check API availability of PropertyWrapper

I found that in Xcode 14.2 (Swift 5.7), the compiler is unable to check the API availability of PropertyWrappers. For example, SwiftUI.StateObject was introduced in iOS 14, but when compiling for iOS 13, the compiler doesn't give an error. This leads to runtime dylib errors.

struct ContentView: View {
    
    class Data: ObservableObject {}
    
    @StateObject private var data = Data() // 🤔️ No compiler error when targeting iOS 13
    
    var body: some View {
        Text("Hello")
    }
}

The app will crash on iOS 13.

dyld: lazy symbol binding failed: Symbol not found: _$s7SwiftUI11StateObjectV12wrappedValueACyxGxyXA_tcfC

However, when we use StateObject in a regular statement, the compiler gives an error as expected. This is the correct behavior.

    init() {
        _data = StateObject(wrappedValue: Data()) // 'StateObject' is only available in iOS 14.0 or newer
    }

So, it seems that the availability check for PropertyWrappers is not working.

Report this here: http://bugreport.apple.com/

Swift 5.7 compiler doesn't check API availability of PropertyWrapper
 
 
Q