Skip to content

Commit 556d8f1

Browse files
committed
Introduce Cauxmparable in place of Comparable in @_implements test.
1 parent 9721dec commit 556d8f1

File tree

1 file changed

+28
-24
lines changed

1 file changed

+28
-24
lines changed

test/attr/attr_implements_fp.swift

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@
1010
// when only known to be comparable".
1111

1212
// Could calls to the different comparison operators.
13-
public var comparedAsComparablesCount : Int = 0
13+
public var comparedAsCauxmparablesCount : Int = 0
1414
public var comparedAsFauxtsCount : Int = 0
1515

16-
public protocol FauxtingPoint : Comparable {
16+
public protocol Cauxmparable {
17+
static func < (lhs: Self, rhs: Self) -> Bool
18+
}
19+
20+
public protocol FauxtingPoint : Cauxmparable {
1721
static var nan: Self { get }
1822
static var one: Self { get }
1923
static var two: Self { get }
@@ -24,11 +28,11 @@ public protocol BinaryFauxtingPoint: FauxtingPoint {
2428
}
2529

2630
public extension BinaryFauxtingPoint {
27-
// This version of < will be called in a context that only knows it has a Comparable.
28-
@_implements(Comparable, <(_:_:))
29-
static func _ComparableLessThan(_ lhs: Fauxt, _ rhs: Fauxt) -> Bool {
30-
print("compared as Comparables")
31-
comparedAsComparablesCount += 1
31+
// This version of < will be called in a context that only knows it has a Cauxmparable.
32+
@_implements(Cauxmparable, <(_:_:))
33+
static func _CauxmparableLessThan(_ lhs: Fauxt, _ rhs: Fauxt) -> Bool {
34+
print("compared as Cauxmparables")
35+
comparedAsCauxmparablesCount += 1
3236
return lhs.bitPattern < rhs.bitPattern
3337
}
3438
}
@@ -73,7 +77,7 @@ public extension Fauxt {
7377
// This version of < will be called in a context that knows it has a Fauxt.
7478
// It is inside an extension of Fauxt rather than the declaration of Fauxt
7579
// itself in order to avoid a warning about near-matches with the defaulted
76-
// requirement from Comparable.< up above.
80+
// requirement from Cauxmparable.< up above.
7781
static func <(_ lhs: Fauxt, _ rhs: Fauxt) -> Bool {
7882
print("compared as Fauxts")
7983
comparedAsFauxtsCount += 1
@@ -85,7 +89,7 @@ public extension Fauxt {
8589
}
8690
}
8791

88-
public func compare_Comparables<T:Comparable>(_ x: T, _ y: T) -> Bool {
92+
public func compare_Cauxmparables<T:Cauxmparable>(_ x: T, _ y: T) -> Bool {
8993
return x < y
9094
}
9195

@@ -98,25 +102,25 @@ public func compare_Fauxts(_ x: Fauxt, _ y: Fauxt) -> Bool {
98102
}
99103

100104
public func main() {
101-
assert(compare_Comparables(Fauxt.one, Fauxt.two))
102-
assert(comparedAsComparablesCount == 1)
103-
// CHECK: compared as Comparables
104-
assert(compare_Comparables(Fauxt.one, Fauxt.nan))
105-
assert(comparedAsComparablesCount == 2)
106-
// CHECK: compared as Comparables
107-
assert(!compare_Comparables(Fauxt.nan, Fauxt.one))
108-
assert(comparedAsComparablesCount == 3)
109-
// CHECK: compared as Comparables
105+
assert(compare_Cauxmparables(Fauxt.one, Fauxt.two))
106+
assert(comparedAsCauxmparablesCount == 1)
107+
// CHECK: compared as Cauxmparables
108+
assert(compare_Cauxmparables(Fauxt.one, Fauxt.nan))
109+
assert(comparedAsCauxmparablesCount == 2)
110+
// CHECK: compared as Cauxmparables
111+
assert(!compare_Cauxmparables(Fauxt.nan, Fauxt.one))
112+
assert(comparedAsCauxmparablesCount == 3)
113+
// CHECK: compared as Cauxmparables
110114

111115
assert(compare_FauxtingPoint(Fauxt.one, Fauxt.two))
112-
assert(comparedAsComparablesCount == 4)
113-
// CHECK: compared as Comparables
116+
assert(comparedAsCauxmparablesCount == 4)
117+
// CHECK: compared as Cauxmparables
114118
assert(compare_FauxtingPoint(Fauxt.one, Fauxt.nan))
115-
assert(comparedAsComparablesCount == 5)
116-
// CHECK: compared as Comparables
119+
assert(comparedAsCauxmparablesCount == 5)
120+
// CHECK: compared as Cauxmparables
117121
assert(!compare_FauxtingPoint(Fauxt.nan, Fauxt.one))
118-
assert(comparedAsComparablesCount == 6)
119-
// CHECK: compared as Comparables
122+
assert(comparedAsCauxmparablesCount == 6)
123+
// CHECK: compared as Cauxmparables
120124

121125
assert(compare_Fauxts(Fauxt.one, Fauxt.two))
122126
assert(comparedAsFauxtsCount == 1)

0 commit comments

Comments
 (0)