[stdlib] Workaround type checker ambiguity in Comparable SwiftNewtypeWrapper

This commit is contained in:
Rintaro Ishizaki
2017-01-25 19:10:32 +09:00
parent 5a4d82716d
commit f11b74176b
2 changed files with 29 additions and 1 deletions

View File

@@ -23,7 +23,7 @@ extension _SwiftNewtypeWrapper where Self.RawValue : Hashable {
% for op in ['<', '>', '<=', '>=']:
public func ${op} <T: _SwiftNewtypeWrapper>(lhs: T, rhs: T) -> Bool
where T.RawValue : Comparable {
where T : Comparable, T.RawValue : Comparable {
return lhs.rawValue ${op} rhs.rawValue
}
% end

View File

@@ -0,0 +1,28 @@
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -I %S/Inputs/custom-modules %s
// REQUIRES: objc_interop
// This test can't use '-verify' mode, because the potential error wouldn't
// belong to any file.
// e.g.:
// <unknown>:0: error: type 'NSNotification.Name' does not conform to protocol 'Comparable'
import Foundation
func acceptEquatable<T: Equatable>(_: T) {}
func acceptHashable<T: Hashable>(_: T) {}
func acceptComparable<T: Comparable>(_: T) {}
func testNewTypeWrapperComparable(x: NSNotification.Name, y: NSNotification.Name) {
acceptEquatable(x)
acceptHashable(x)
acceptComparable(x)
_ = x == y
_ = x != y
_ = x.hashValue
_ = x < y
_ = x > y
_ = x <= y
_ = x >= y
_ = x as NSString
}