blob: c8f088dc7afb827cac1617b4352a9eed0ec646c4 [file] [log] [blame]
Dan Willemsenbc60c3c2021-12-15 01:09:00 -08001// run -gcflags="-G=3"
2
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.
6
7package main
8
9import (
10 "encoding/json"
11)
12
13type A[T any] struct {
14 F1 string `json:"t1"`
15 F2 T `json:"t2"`
16 B B `json:"t3"`
17}
18
19type B struct {
20 F4 int `json:"t4"`
21}
22
23func a[T any]() {
24 data := `{"t1":"1","t2":2,"t3":{"t4":4}}`
25 a1 := A[T]{}
26 if err := json.Unmarshal([]byte(data), &a1); err != nil {
27 panic(err)
28 }
29 if bytes, err := json.Marshal(&a1); err != nil {
30 panic(err)
31 } else if string(bytes) != data {
32 panic(string(bytes))
33 }
34}
35
36func main() {
37 a[int]()
38}