...
1
2
3
4
5 package p
6
7 import "fmt"
8
9 type Interface[T any] interface {
10 m(Interface[T])
11 }
12
13 func f[S []Interface[T], T any](S) {}
14
15 func _() {
16 var s []Interface[int]
17 f(s)
18 }
19
20
21
22 type InterfaceA[T comparable] interface {
23 setData(string) InterfaceA[T]
24 }
25
26 type ImplA[T comparable] struct {
27 data string
28 args []any
29 }
30
31 func NewInterfaceA[T comparable](args ...any) InterfaceA[T] {
32 return &ImplA[T]{
33 data: fmt.Sprintf("%v", args...),
34 args: args,
35 }
36 }
37
38 func (k *ImplA[T]) setData(data string) InterfaceA[T] {
39 k.data = data
40 return k
41 }
42
43 func Foo[M ~map[InterfaceA[T]]V, T comparable, V any](m M) {
44
45 return
46 }
47
48 func Bar() {
49 keys := make([]InterfaceA[int], 0, 10)
50 m := make(map[InterfaceA[int]]int)
51 for i := 0; i < 10; i++ {
52 keys = append(keys, NewInterfaceA[int](i))
53 m[keys[i]] = i
54 }
55
56 Foo(m)
57 }
58
View as plain text