File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -54,6 +54,32 @@ func main() {
5454 if len (out ) != 1 || out [0 ].Int () != 15 {
5555 panic (fmt .Sprintf ("reflect closure call failed: got %v" , out ))
5656 }
57+
58+ // More complex closure calls: multi-args / multi-returns with free vars.
59+ base := 7
60+ scale := 3
61+ mix := func (a , b int , tag string ) (int , string ) {
62+ return base + a * scale + b , fmt .Sprintf ("%s:%d" , tag , base )
63+ }
64+ vmix := reflect .ValueOf (mix )
65+ mout := vmix .Call ([]reflect.Value {
66+ reflect .ValueOf (2 ),
67+ reflect .ValueOf (5 ),
68+ reflect .ValueOf ("k" ),
69+ })
70+ if len (mout ) != 2 || mout [0 ].Int () != 18 || mout [1 ].String () != "k:7" {
71+ panic (fmt .Sprintf ("reflect closure multi call failed: got %v" , mout ))
72+ }
73+
74+ offset := 100
75+ swapAdd := func (a int , b int ) (int , int ) {
76+ return b + offset , a + offset
77+ }
78+ vswap := reflect .ValueOf (swapAdd )
79+ sout := vswap .Call ([]reflect.Value {reflect .ValueOf (1 ), reflect .ValueOf (9 )})
80+ if len (sout ) != 2 || sout [0 ].Int () != 109 || sout [1 ].Int () != 101 {
81+ panic (fmt .Sprintf ("reflect closure swap call failed: got %v" , sout ))
82+ }
5783}
5884
5985type T struct {
You can’t perform that action at this time.
0 commit comments