Debian Codegraph @

test/typeparam/pair.go

raw
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 "fmt"
11 "unsafe"
12 )
13
14 type pair[F1, F2 any] struct {
15 f1 F1
16 f2 F2
17 }
18
19 func main() {
20 p := pair[int32, int64]{1, 2}
21 if got, want := unsafe.Sizeof(p.f1), uintptr(4); got != want {
22 panic(fmt.Sprintf("unexpected f1 size == %d, want %d", got, want))
23 }
24 if got, want := unsafe.Sizeof(p.f2), uintptr(8); got != want {
25 panic(fmt.Sprintf("unexpected f2 size == %d, want %d", got, want))
26 }
27
28 type mypair struct {
29 f1 int32
30 f2 int64
31 }
32 mp := mypair(p)
33 if mp.f1 != 1 || mp.f2 != 2 {
34 panic(fmt.Sprintf("mp == %#v, want %#v", mp, mypair{1, 2}))
35 }
36 }