1
1
// RUN: %empty-directory(%t)
2
2
// RUN: echo 'main()' >%t/main.swift
3
- // RUN: %target-build-swift -o %t/a.out %s %t/main.swift -Xfrontend -enable-operator-designated-types -Xfrontend -solver-enable-operator-designated-types
3
+ // RUN: %target-swiftc_driver -o %t/a.out %s %t/main.swift
4
4
// RUN: %target-codesign %t/a.out
5
5
// RUN: %target-run %t/a.out | %FileCheck %s
6
6
// REQUIRES: executable_test
10
10
// when only known to be comparable".
11
11
12
12
// Could calls to the different comparison operators.
13
- public var comparedAsCauxmparablesCount : Int = 0
13
+ public var comparedAsComparablesCount : Int = 0
14
14
public var comparedAsFauxtsCount : Int = 0
15
15
16
- infix operator .< : ComparisonPrecedence, BinaryFauxtingPoint, Cauxmparable
17
-
18
- public protocol Cauxmparable {
19
- static func .< ( lhs: Self , rhs: Self ) -> Bool
20
- }
21
-
22
- public protocol FauxtingPoint : Cauxmparable {
16
+ public protocol FauxtingPoint : Comparable {
23
17
static var nan : Self { get }
24
18
static var one : Self { get }
25
19
static var two : Self { get }
26
20
}
27
21
28
22
public protocol BinaryFauxtingPoint : FauxtingPoint {
29
- @_nonoverride static func .< ( lhs: Self , rhs: Self ) -> Bool
30
-
31
23
var bitPattern : UInt8 { get }
32
24
}
33
25
34
26
public extension BinaryFauxtingPoint {
35
- // This version of . < will be called in a context that only knows it has a Cauxmparable .
36
- @_implements ( Cauxmparable , . < ( _: _: ) )
37
- static func _CauxmparableLessThan ( _ lhs: Fauxt , _ rhs: Fauxt ) -> Bool {
38
- print ( " compared as Cauxmparables " )
39
- comparedAsCauxmparablesCount += 1
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
40
32
return lhs. bitPattern < rhs. bitPattern
41
33
}
42
34
}
@@ -78,11 +70,11 @@ extension Fauxt: BinaryFauxtingPoint {
78
70
}
79
71
80
72
public extension Fauxt {
81
- // This version of . < will be called in a context that knows it has a Fauxt.
73
+ // This version of < will be called in a context that knows it has a Fauxt.
82
74
// It is inside an extension of Fauxt rather than the declaration of Fauxt
83
75
// itself in order to avoid a warning about near-matches with the defaulted
84
- // requirement from Cauxmparable. .< up above.
85
- static func . < ( _ lhs: Fauxt , _ rhs: Fauxt ) -> Bool {
76
+ // requirement from Comparable .< up above.
77
+ static func < ( _ lhs: Fauxt , _ rhs: Fauxt ) -> Bool {
86
78
print ( " compared as Fauxts " )
87
79
comparedAsFauxtsCount += 1
88
80
if lhs. state == . Nan || rhs. state == . Nan {
@@ -93,42 +85,24 @@ public extension Fauxt {
93
85
}
94
86
}
95
87
96
- public func compare_Cauxmparables< T: Cauxmparable > ( _ x: T , _ y: T ) -> Bool {
97
- return x .< y
98
- }
99
-
100
- public func compare_FauxtingPoint< T: FauxtingPoint > ( _ x: T , _ y: T ) -> Bool {
101
- return x .< y
102
- }
103
-
104
- public func compare_BinaryFauxtingPoint< T: BinaryFauxtingPoint > ( _ x: T , _ y: T ) -> Bool {
105
- return x .< y
88
+ public func compare_Comparables< T: Comparable > ( _ x: T , _ y: T ) -> Bool {
89
+ return x < y
106
90
}
107
91
108
92
public func compare_Fauxts( _ x: Fauxt , _ y: Fauxt ) -> Bool {
109
- return x . < y
93
+ return x < y
110
94
}
111
95
112
96
public func main( ) {
113
- assert ( compare_Cauxmparables ( Fauxt . one, Fauxt . two) )
114
- assert ( comparedAsCauxmparablesCount == 1 )
115
- // CHECK: compared as Cauxmparables
116
- assert ( compare_Cauxmparables ( Fauxt . one, Fauxt . nan) )
117
- assert ( comparedAsCauxmparablesCount == 2 )
118
- // CHECK: compared as Cauxmparables
119
- assert ( !compare_Cauxmparables( Fauxt . nan, Fauxt . one) )
120
- assert ( comparedAsCauxmparablesCount == 3 )
121
- // CHECK: compared as Cauxmparables
122
-
123
- assert ( compare_FauxtingPoint ( Fauxt . one, Fauxt . two) )
124
- assert ( comparedAsCauxmparablesCount == 4 )
125
- // CHECK: compared as Cauxmparables
126
- assert ( compare_FauxtingPoint ( Fauxt . one, Fauxt . nan) )
127
- assert ( comparedAsCauxmparablesCount == 5 )
128
- // CHECK: compared as Cauxmparables
129
- assert ( !compare_FauxtingPoint( Fauxt . nan, Fauxt . one) )
130
- assert ( comparedAsCauxmparablesCount == 6 )
131
- // CHECK: compared as Cauxmparables
97
+ assert ( compare_Comparables ( Fauxt . one, Fauxt . two) )
98
+ assert ( comparedAsComparablesCount == 1 )
99
+ // CHECK: compared as Comparables
100
+ assert ( compare_Comparables ( Fauxt . one, Fauxt . nan) )
101
+ assert ( comparedAsComparablesCount == 2 )
102
+ // CHECK: compared as Comparables
103
+ assert ( !compare_Comparables( Fauxt . nan, Fauxt . one) )
104
+ assert ( comparedAsComparablesCount == 3 )
105
+ // CHECK: compared as Comparables
132
106
133
107
assert ( compare_Fauxts ( Fauxt . one, Fauxt . two) )
134
108
assert ( comparedAsFauxtsCount == 1 )
@@ -139,15 +113,4 @@ public func main() {
139
113
assert ( !compare_Fauxts( Fauxt . nan, Fauxt . one) )
140
114
assert ( comparedAsFauxtsCount == 3 )
141
115
// CHECK: compared as Fauxts
142
-
143
- assert ( compare_BinaryFauxtingPoint ( Fauxt . one, Fauxt . two) )
144
- assert ( comparedAsFauxtsCount == 4 )
145
- // CHECK: compared as Fauxts
146
- assert ( !compare_BinaryFauxtingPoint( Fauxt . one, Fauxt . nan) )
147
- assert ( comparedAsFauxtsCount == 5 )
148
- // CHECK: compared as Fauxts
149
- assert ( !compare_BinaryFauxtingPoint( Fauxt . nan, Fauxt . one) )
150
- assert ( comparedAsFauxtsCount == 6 )
151
- // CHECK: compared as Fauxts
152
-
153
116
}
0 commit comments