This code causes abort trap 6 in Xcode 13 and in Xcode 14 beta 6 causes "Command CompileSwift failed with a nonzero exit code"
///
protocol Wrapper {
associatedtype Wrapped
var wrapped: Wrapped { get }
}
///
struct SimpleWrapper <Wrapped>: Wrapper {
var wrapped: Wrapped
}
///
func unwrap <T: Wrapper> (_ wrapper: T) -> T.Wrapped {
wrapper.wrapped
}
///
extension Wrapper where Self == SimpleWrapper<Wrapped> {
static func simple (_ value: Wrapped) -> Self {
SimpleWrapper<Wrapped>(wrapped: value)
}
}
///
func demo () -> Int {
unwrap(.simple(0))
}
Even better than giving a more helpful error message would be that this code compiled and worked I think I see what about it makes it tricky, but I also think I see no logical holes, i.e., in theory, logically speaking, this code could work, not speaking to how much compiler development would remain to be done.