Source file test/typeparam/issue48318.go

     1  // run
     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  
     7  package main
     8  
     9  import (
    10  	"encoding/xml"
    11  	"fmt"
    12  )
    13  
    14  type A[T, U any] struct {
    15  	Name T `xml:"name"`
    16  	Data U `xml:"data"`
    17  }
    18  
    19  func main() {
    20  	src := &A[string, int]{Name: "name", Data: 1}
    21  	data, err := xml.Marshal(src)
    22  	if err != nil {
    23  		panic(err)
    24  	}
    25  	dst := &A[string, int]{}
    26  	err = xml.Unmarshal(data, dst)
    27  	if err != nil {
    28  		panic(err)
    29  	}
    30  	if *src != *dst {
    31  		panic(fmt.Sprintf("wanted %#v got %#v", src, dst))
    32  	}
    33  }
    34  

View as plain text