Compiler crash with protocol extension

With:


protocol HashValue {
    func hashValue() -> Int
}

extension HashValue where Self: Optional<Hashable> {
    func hashValue() -> Int {
        guard let self = self else {
            return 1
        }
        return hashValue
    }
}


I get a compiler crash, Xcode 7b4, with the error message:


<unknown>:0: error: type 'Self' constrained to non-protocol type 'Optional<Hashable>'


Which obviously is a compiler bug, compilers should crash! However:


  1. Where do you report crashes? Xcode doesn't seem to have a crash reporting feature!
  2. Should the code compile? `extension HashValue where Self == Optional<Hashable>` doesn't!
  3. Is there a way of doing an extension constrained to an optional?

You can make a protocol that Optionals conform to, and constrain to that.

You can report bugs at the Bug Reporter site. There is also a link at the bottom of every page in the forums.

Report bugs (crashes, etc.) at bugreport.apple.com (or use the "Report Bugs" link at the bottom of the pages here on the Developer Center, which takes you to a landing page with a sign in link for bugreport.apple.com).

I have tried this:


extension Optional: HashValue where T: Hashable {
    func hashValue() -> Int {
        switch self {
        case let .Some(t):
            return t.hashValue
        case .None:
            return 1
        }
    }
}


But that gives the error:


Extension of type 'Optional' with constraints cannot have an inheritance clause


Did you have something else in mind.

Thanks rdr: 22146058

Compiler crash with protocol extension
 
 
Q