Abort trap 6/nonzero exit code

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 :pray: 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.

On the latest 5.7 nightly build and main I see:

17:19: error: same-type constraint 'Self' == 'SimpleWrapper<Self.Wrapped>' is recursive
extension Wrapper where Self == SimpleWrapper<Wrapped> {
                  ^
5:5: error: type of expression is ambiguous without more context
    unwrap(.simple(0))
    ^~~~~~~~~~~~~~~~~~

On Xcode 14 RC it does result in a crash.

1 Like