3 // Copyright 2021 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
7 // comparisons of type parameters to interfaces
11 func f[T comparable](t, u T) bool {
12 // Comparing two type parameters directly.
13 // (Not really testing comparisons to interfaces, but just 'cause we're here.)
17 func g[T comparable](t T, i interface{}) bool {
18 // Compare type parameter value to empty interface.
31 func h[T C](t T, i I) bool {
32 // Compare type parameter value to nonempty interface.
38 func (x myint) foo() {
41 func k[T comparable](t T, i interface{}) bool {
42 // Compare derived type value to interface.
43 return struct{ a, b T }{t, t} == i
51 assert(h(myint(3), myint(3)))
52 assert(!h(myint(3), myint(5)))
54 type S struct{ a, b float64 }
56 assert(f(S{3, 5}, S{3, 5}))
57 assert(!f(S{3, 5}, S{4, 6}))
58 assert(g(S{3, 5}, S{3, 5}))
59 assert(!g(S{3, 5}, S{4, 6}))
61 assert(k(3, struct{ a, b int }{3, 3}))
62 assert(!k(3, struct{ a, b int }{3, 4}))
67 panic("assertion failed")