1
1
// RUN: %empty-directory(%t)
2
2
// RUN: echo 'main()' >%t/main.swift
3
- // RUN: %target-swiftc_driver -o %t/a.out %s %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
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 comparedAsComparablesCount : Int = 0
13
+ public var comparedAsCauxmparablesCount : Int = 0
14
14
public var comparedAsFauxtsCount : Int = 0
15
15
16
- public protocol FauxtingPoint : Comparable {
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 {
17
23
static var nan : Self { get }
18
24
static var one : Self { get }
19
25
static var two : Self { get }
20
26
}
21
27
22
28
public protocol BinaryFauxtingPoint : FauxtingPoint {
29
+ @_nonoverride static func .< ( lhs: Self , rhs: Self ) -> Bool
30
+
23
31
var bitPattern : UInt8 { get }
24
32
}
25
33
26
34
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
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
32
40
return lhs. bitPattern < rhs. bitPattern
33
41
}
34
42
}
@@ -70,11 +78,11 @@ extension Fauxt: BinaryFauxtingPoint {
70
78
}
71
79
72
80
public extension Fauxt {
73
- // This version of < will be called in a context that knows it has a Fauxt.
81
+ // This version of . < will be called in a context that knows it has a Fauxt.
74
82
// It is inside an extension of Fauxt rather than the declaration of Fauxt
75
83
// itself in order to avoid a warning about near-matches with the defaulted
76
- // requirement from Comparable .< up above.
77
- static func < ( _ lhs: Fauxt , _ rhs: Fauxt ) -> Bool {
84
+ // requirement from Cauxmparable. .< up above.
85
+ static func . < ( _ lhs: Fauxt , _ rhs: Fauxt ) -> Bool {
78
86
print ( " compared as Fauxts " )
79
87
comparedAsFauxtsCount += 1
80
88
if lhs. state == . Nan || rhs. state == . Nan {
@@ -85,24 +93,42 @@ public extension Fauxt {
85
93
}
86
94
}
87
95
88
- public func compare_Comparables< T: Comparable > ( _ x: T , _ y: T ) -> Bool {
89
- return x < y
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
90
106
}
91
107
92
108
public func compare_Fauxts( _ x: Fauxt , _ y: Fauxt ) -> Bool {
93
- return x < y
109
+ return x . < y
94
110
}
95
111
96
112
public func main( ) {
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
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
106
132
107
133
assert ( compare_Fauxts ( Fauxt . one, Fauxt . two) )
108
134
assert ( comparedAsFauxtsCount == 1 )
@@ -113,4 +139,15 @@ public func main() {
113
139
assert ( !compare_Fauxts( Fauxt . nan, Fauxt . one) )
114
140
assert ( comparedAsFauxtsCount == 3 )
115
141
// 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
+
116
153
}
0 commit comments