       return nil
     }
 
-    if let result = Self(rawValue: _bridgedNSError.code) {
-      self = result
-    } else {
+    self.init(rawValue: RawValue(IntMax(_bridgedNSError.code)))
+  }
+
+  public final var hashValue: Int { return _code }
+}
+
+#if false
+// Allow two bridged NSError types to be compared.
+public func ==<T: __BridgedNSError where T.RawValue: UnsignedIntegerType>(
+  lhs: T,
+  rhs: T
+) -> Bool {
+  return lhs.rawValue.toUIntMax() == rhs.rawValue.toUIntMax()
+}
+
+
+// rdar://problem/21027215 prevents this
+public extension __BridgedNSError where RawValue: UnsignedIntegerType {
+  public final var _domain: String { return Self._NSErrorDomain }
+  public final var _code: Int {
+    return Int(bitPattern: UInt(rawValue.toUIntMax()))
+  }
+
+  public init?(rawValue: RawValue) {
+    self = unsafeBitCast(rawValue, Self.self)
+  }
+
+  public init?(_bridgedNSError: NSError) {
+    if _bridgedNSError.domain != Self._NSErrorDomain {
       return nil
     }
-  }
-
-  public final var hashValue: Int { return rawValue }
-}
+
+    self.init(rawValue: RawValue(UIntMax(UInt(_bridgedNSError.code))))
+  }
+
+  public final var hashValue: Int { return _code }
+}
+#endif
 
 /// Describes a raw representable type that is bridged to a particular
 /// NSError domain.

}

// Allow two bridged NSError types to be compared.
public func ==<T: __BridgedNSError where T.RawValue == Int>(
  lhs: T,
  rhs: T
) -> Bool {
  return lhs.rawValue == rhs.rawValue
}

public extension __BridgedNSError where RawValue == Int {
  public final var _domain: String { return Self._NSErrorDomain }
  public final var _code: Int { return rawValue }

  public init?(rawValue: Int) {
    self = unsafeBitCast(rawValue, Self.self)
  }


  public static var _NSErrorDomain: String { return NSURLErrorDomain }
}

extension POSIXError : _BridgedNSError {
  public static var _NSErrorDomain: String { return NSPOSIXErrorDomain }
}

extension MachError : _BridgedNSError {
  public static var _NSErrorDomain: String { return NSMachErrorDomain }
}
