mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[stdlib] Workaround type checker ambiguity in Comparable SwiftNewtypeWrapper
This commit is contained in:
@@ -23,7 +23,7 @@ extension _SwiftNewtypeWrapper where Self.RawValue : Hashable {
|
|||||||
|
|
||||||
% for op in ['<', '>', '<=', '>=']:
|
% for op in ['<', '>', '<=', '>=']:
|
||||||
public func ${op} <T: _SwiftNewtypeWrapper>(lhs: T, rhs: T) -> Bool
|
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
|
return lhs.rawValue ${op} rhs.rawValue
|
||||||
}
|
}
|
||||||
% end
|
% end
|
||||||
|
|||||||
28
test/ClangImporter/newtype_conformance.swift
Normal file
28
test/ClangImporter/newtype_conformance.swift
Normal 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
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user