Debian Codegraph @

staticcheck/sa1026/testdata/go1.18/CheckUnsupportedMarshal/generics.go

raw
1 package pkg
2
3 import (
4 "encoding/json"
5 "encoding/xml"
6 )
7
8 type LMap[K comparable, V any] struct {
9 M1 map[K]V
10 M2 map[K]chan int
11 }
12
13 func (lm *LMap[K, V]) MarshalJSON() {
14 json.Marshal(lm.M1)
15 json.Marshal(lm.M2) //@ diag(`unsupported type`)
16 }
17
18 func recursiveGeneric() {
19 // don't recurse infinitely
20 var t Tree[int]
21 json.Marshal(t)
22 xml.Marshal(t)
23 }
24
25 type Tree[T any] struct {
26 Node *Node[T]
27 }
28
29 type Node[T any] struct {
30 Tree *Tree[T]
31 }