Source file test/fixedbugs/issue53137.go

     1  // run
     2  
     3  // Copyright 2022 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  	"unsafe"
    11  )
    12  
    13  type Embedded struct {
    14  	B int
    15  }
    16  
    17  type S[K any] struct {
    18  	A K
    19  	Embedded
    20  }
    21  
    22  func showOffsets[K any](d *S[K]) {
    23  	o1 := unsafe.Offsetof(d.B)
    24  	o2 := unsafe.Offsetof(d.Embedded)
    25  	if o1 != o2 {
    26  		panic("offset mismatch")
    27  	}
    28  }
    29  
    30  func main() {
    31  	showOffsets(new(S[int]))
    32  }
    33  

View as plain text