github.com/powerman/golang-tools@v0.1.11-0.20220410185822-5ad214d8d803/go/pointer/testdata/chanreflect1.go (about) 1 // +build ignore 2 3 package main 4 5 import "reflect" 6 7 // 8 // This test is very sensitive to line-number perturbations! 9 10 // Test of channels with reflection. 11 12 var a, b int 13 14 func chanreflect1() { 15 ch := make(chan *int, 0) 16 crv := reflect.ValueOf(ch) 17 crv.Send(reflect.ValueOf(&a)) 18 print(crv.Interface()) // @types chan *int 19 print(crv.Interface().(chan *int)) // @pointsto makechan@testdata/chanreflect.go:15:12 20 print(<-ch) // @pointsto main.a 21 } 22 23 func chanreflect2() { 24 ch := make(chan *int, 0) 25 ch <- &b 26 crv := reflect.ValueOf(ch) 27 r, _ := crv.Recv() 28 print(r.Interface()) // @types *int 29 print(r.Interface().(*int)) // @pointsto main.b 30 } 31 32 func main() { 33 chanreflect1() 34 chanreflect2() 35 }