codekingpro/portable-devtools
114k
1// run2 3// Copyright 2021 The Go Authors. All rights reserved.4// Use of this source code is governed by a BSD-style5// license that can be found in the LICENSE file.6 7package main8 9import (10 "fmt"11 "unsafe"12)13 14type pair[F1, F2 any] struct {15 f1 F116 f2 F217}18 19func 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 int3230 f2 int6431 }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}37 