@@ -133,6 +133,69 @@ func detectValue() {
133
133
valueTest (0 , 5 , "variadic value 5" ) // want `false`
134
134
}
135
135
136
+ func detectComparable () {
137
+ typeTest ("" , "comparable" ) // want `true`
138
+ typeTest (0 , "comparable" ) // want `true`
139
+
140
+ type good1 struct {
141
+ x , y int
142
+ }
143
+ type good2 struct {
144
+ nested good1
145
+ x [2 ]byte
146
+ s string
147
+ }
148
+ type good3 struct {
149
+ x * int
150
+ }
151
+ type good4 struct {
152
+ * good3
153
+ good2
154
+ }
155
+
156
+ typeTest (good1 {}, "comparable" ) // want `true`
157
+ typeTest (good2 {}, "comparable" ) // want `true`
158
+ typeTest (good3 {}, "comparable" ) // want `true`
159
+ typeTest (good4 {}, "comparable" ) // want `true`
160
+ typeTest (& good1 {}, "comparable" ) // want `true`
161
+ typeTest (& good2 {}, "comparable" ) // want `true`
162
+ typeTest (& good3 {}, "comparable" ) // want `true`
163
+ typeTest (& good4 {}, "comparable" ) // want `true`
164
+
165
+ var (
166
+ g1 good1
167
+ g2 good2
168
+ g3 good3
169
+ g4 good4
170
+ )
171
+ _ = g1 == good1 {}
172
+ _ = g2 == good2 {}
173
+ _ = g3 == good3 {}
174
+ _ = g4 == good4 {}
175
+ _ = g1 != good1 {}
176
+ _ = g2 != good2 {}
177
+ _ = g3 != good3 {}
178
+ _ = g4 != good4 {}
179
+
180
+ type bad1 struct {
181
+ _ [1 ]func ()
182
+ }
183
+ type bad2 struct {
184
+ slice []int
185
+ }
186
+ type bad3 struct {
187
+ bad2
188
+ }
189
+
190
+ typeTest (bad1 {}, "comparable" )
191
+ typeTest (bad2 {}, "comparable" )
192
+ typeTest (bad3 {}, "comparable" )
193
+
194
+ typeTest (& bad1 {}, "comparable" ) // want `true`
195
+ typeTest (& bad2 {}, "comparable" ) // want `true`
196
+ typeTest (& bad3 {}, "comparable" ) // want `true`
197
+ }
198
+
136
199
func detectType () {
137
200
{
138
201
var s fmt.Stringer
0 commit comments