Source file
test/abi/method_wrapper_notinheap.go
1
2
3
4
5
6
7
8
9 package main
10
11 import (
12 "reflect"
13 "runtime/cgo"
14 )
15
16 type E struct {
17 x int
18 }
19
20 func (e *E) M() int {
21 return e.x
22 }
23
24 type T struct {
25 E
26 }
27
28 type NotInHeapT struct {
29 E
30 _ cgo.Incomplete
31 }
32
33 var (
34 x = struct {
35 E
36 _ cgo.Incomplete
37 }{E: E{x: 7}}
38 tFn = (*T).M
39 notInHeapTFn = (*NotInHeapT).M
40 )
41
42 type I interface {
43 M() int
44 }
45
46
47 func call(i I) int {
48 return i.M()
49 }
50
51 func main() {
52 if got := call(&x); got != 7 {
53 panic(got)
54 }
55 if reflect.ValueOf(tFn).Pointer() == reflect.ValueOf(notInHeapTFn).Pointer() {
56 panic("pointer and scalar receiver wrappers were shared")
57 }
58 }
59
View as plain text