| 1 |
// Copyright 2021 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
package main |
| 6 |
|
| 7 |
import ( |
| 8 |
"./a" |
| 9 |
"fmt" |
| 10 |
"unsafe" |
| 11 |
) |
| 12 |
|
| 13 |
func main() { |
| 14 |
p := a.Pair[int32, int64]{1, 2} |
| 15 |
if got, want := unsafe.Sizeof(p.Field1), uintptr(4); got != want { |
| 16 |
panic(fmt.Sprintf("unexpected f1 size == %d, want %d", got, want)) |
| 17 |
} |
| 18 |
if got, want := unsafe.Sizeof(p.Field2), uintptr(8); got != want { |
| 19 |
panic(fmt.Sprintf("unexpected f2 size == %d, want %d", got, want)) |
| 20 |
} |
| 21 |
|
| 22 |
type mypair struct { |
| 23 |
Field1 int32 |
| 24 |
Field2 int64 |
| 25 |
} |
| 26 |
mp := mypair(p) |
| 27 |
if mp.Field1 != 1 || mp.Field2 != 2 { |
| 28 |
panic(fmt.Sprintf("mp == %#v, want %#v", mp, mypair{1, 2})) |
| 29 |
} |
| 30 |
} |