7 // Test of channels with reflection.
12 ch := make(chan *int, 0) // @line cr1make
13 crv := reflect.ValueOf(ch)
14 crv.Send(reflect.ValueOf(&a))
15 print(crv.Interface()) // @types chan *int
16 print(crv.Interface().(chan *int)) // @pointsto makechan@cr1make:12
17 print(<-ch) // @pointsto main.a
20 func chanreflect1i() {
21 // Exercises reflect.Value conversions to/from interfaces:
22 // a different code path than for concrete types.
23 ch := make(chan interface{}, 0)
24 reflect.ValueOf(ch).Send(reflect.ValueOf(&a))
26 print(v) // @types *int
27 print(v.(*int)) // @pointsto main.a
31 ch := make(chan *int, 0)
33 crv := reflect.ValueOf(ch)
35 print(r.Interface()) // @types *int
36 print(r.Interface().(*int)) // @pointsto main.b
40 // MakeChan(<-chan) is a no-op.
41 t := reflect.ChanOf(reflect.RecvDir, reflect.TypeOf(&a))
42 print(reflect.Zero(t).Interface()) // @types <-chan *int
43 print(reflect.MakeChan(t, 0).Interface().(<-chan *int)) // @pointsto
44 print(reflect.MakeChan(t, 0).Interface().(chan *int)) // @pointsto
48 // MakeChan(chan<-) is a no-op.
49 t := reflect.ChanOf(reflect.SendDir, reflect.TypeOf(&a))
50 print(reflect.Zero(t).Interface()) // @types chan<- *int
51 print(reflect.MakeChan(t, 0).Interface().(chan<- *int)) // @pointsto
52 print(reflect.MakeChan(t, 0).Interface().(chan *int)) // @pointsto
56 t := reflect.ChanOf(reflect.BothDir, reflect.TypeOf(&a))
57 print(reflect.Zero(t).Interface()) // @types chan *int
58 ch := reflect.MakeChan(t, 0)
59 print(ch.Interface().(chan *int)) // @pointsto <alloc in reflect.MakeChan>
60 ch.Send(reflect.ValueOf(&b))
61 ch.Interface().(chan *int) <- &a
63 print(r.Interface().(*int)) // @pointsto main.a | main.b
64 print(<-ch.Interface().(chan *int)) // @pointsto main.a | main.b
67 var unknownDir reflect.ChanDir // not a constant
69 func chanOfUnknown() {
70 // Unknown channel direction: assume all three.
71 // MakeChan only works on the bi-di channel type.
72 t := reflect.ChanOf(unknownDir, reflect.TypeOf(&a))
73 print(reflect.Zero(t).Interface()) // @types <-chan *int | chan<- *int | chan *int
74 print(reflect.MakeChan(t, 0).Interface()) // @types chan *int