1
2
3
4
5 package p
6
7 type S struct{}
8
9 func (*S) m(int) {}
10
11 func f[A interface {
12 ~*B
13 m(C)
14 }, B, C any]() {
15 }
16
17 var _ = f[*S]
18
19
20
21 type ptrTo[A any] interface{ ~*A }
22 type hasFoo[A any] interface{ foo(A) }
23 type both[A, B any] interface {
24 ptrTo[A]
25 hasFoo[B]
26 }
27
28 type fooer[A any] struct{}
29
30 func (f *fooer[A]) foo(A) {}
31
32 func withPtr[A ptrTo[B], B any]() {}
33 func withFoo[A hasFoo[B], B any]() {}
34 func withBoth[A both[B, C], B, C any]() {}
35
36 func _() {
37 withPtr[*fooer[int]]()
38 withFoo[*fooer[int]]()
39 withBoth[*fooer[int]]()
40 }
41
42
43
44 type X struct{}
45
46 func (x X) M() int { return 42 }
47
48 func CallM1[T interface{ M() R }, R any](t T) R {
49 return t.M()
50 }
51
52 func CallM2[T interface {
53 X
54 M() R
55 }, R any](t T) R {
56 return t.M()
57 }
58
59 func _() {
60 CallM1(X{})
61 CallM2(X{})
62 }
63
View as plain text