honnef.co/go/tools@v0.4.7/staticcheck/testdata/src/example.com/CheckUnsupportedMarshal/generics.go (about) 1 //go:build go1.18 2 3 package pkg 4 5 import ( 6 "encoding/json" 7 "encoding/xml" 8 ) 9 10 type LMap[K comparable, V any] struct { 11 M1 map[K]V 12 M2 map[K]chan int 13 } 14 15 func (lm *LMap[K, V]) MarshalJSON() { 16 json.Marshal(lm.M1) 17 json.Marshal(lm.M2) //@ diag(`unsupported type`) 18 } 19 20 func recursiveGeneric() { 21 // don't recurse infinitely 22 var t Tree[int] 23 json.Marshal(t) 24 xml.Marshal(t) 25 } 26 27 type Tree[T any] struct { 28 Node *Node[T] 29 } 30 31 type Node[T any] struct { 32 Tree *Tree[T] 33 }