When using implicitly unwrapped optionals, the priority of protocol extensions seems to be wrong. Consider this example:
import SwiftUI
protocol SpecializedView: View {}
struct MyView: SpecializedView {
var body: some View {
EmptyView()
}
}
extension View {
var isSpecialized: Bool {
false
}
}
extension SpecializedView {
var isSpecialized: Bool {
true
}
}
I've only been able to reproduce the issue with SwiftUI Views. This is a minimally working example that exhibits the behavior:
@main
struct ProtocolExtensions: App {
var body: some Scene {
WindowGroup {
Button("Test") {
let view1: MyView = MyView()
let view2: MyView? = MyView()
let view3: MyView! = MyView()
print(view1.isSpecialized) // true
print(view2.isSpecialized) // false -> Why does this compile?
print(view2!.isSpecialized) // true
print(view3.isSpecialized) // false
print(view3!.isSpecialized) // true
}
}
}
}
Is this a bug? I'm using Xcode 13.2.1