Skip to content

Commit f11b741

Browse files
committed
[stdlib] Workaround type checker ambiguity in Comparable SwiftNewtypeWrapper
1 parent 5a4d827 commit f11b741

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

stdlib/public/core/NewtypeWrapper.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ extension _SwiftNewtypeWrapper where Self.RawValue : Hashable {
2323

2424
% for op in ['<', '>', '<=', '>=']:
2525
public func ${op} <T: _SwiftNewtypeWrapper>(lhs: T, rhs: T) -> Bool
26-
where T.RawValue : Comparable {
26+
where T : Comparable, T.RawValue : Comparable {
2727
return lhs.rawValue ${op} rhs.rawValue
2828
}
2929
% end
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -I %S/Inputs/custom-modules %s
2+
// REQUIRES: objc_interop
3+
4+
// This test can't use '-verify' mode, because the potential error wouldn't
5+
// belong to any file.
6+
// e.g.:
7+
// <unknown>:0: error: type 'NSNotification.Name' does not conform to protocol 'Comparable'
8+
9+
import Foundation
10+
11+
func acceptEquatable<T: Equatable>(_: T) {}
12+
func acceptHashable<T: Hashable>(_: T) {}
13+
func acceptComparable<T: Comparable>(_: T) {}
14+
15+
func testNewTypeWrapperComparable(x: NSNotification.Name, y: NSNotification.Name) {
16+
acceptEquatable(x)
17+
acceptHashable(x)
18+
acceptComparable(x)
19+
20+
_ = x == y
21+
_ = x != y
22+
_ = x.hashValue
23+
_ = x < y
24+
_ = x > y
25+
_ = x <= y
26+
_ = x >= y
27+
_ = x as NSString
28+
}

0 commit comments

Comments
 (0)