]> Cypherpunks repositories - gostls13.git/commitdiff
reflect: test using a MakeFunc value in a couple of different ways
authorIan Lance Taylor <iant@golang.org>
Fri, 4 Oct 2013 20:12:50 +0000 (13:12 -0700)
committerIan Lance Taylor <iant@golang.org>
Fri, 4 Oct 2013 20:12:50 +0000 (13:12 -0700)
The gccgo implementation mishandled calling Interface on a
value created by MakeFunc.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/14401043

src/pkg/reflect/all_test.go
src/pkg/reflect/makefunc.go

index 6e485c1e6b7027fb24d336a7b5ffc5cba293ddf8..e9a20963fb96d9f38c30548954fdb3c02e45a088 100644 (file)
@@ -1452,6 +1452,24 @@ func TestMakeFunc(t *testing.T) {
        }
 }
 
+func TestMakeFuncInterface(t *testing.T) {
+       fn := func(i int) int { return i }
+       incr := func(in []Value) []Value {
+               return []Value{ValueOf(int(in[0].Int() + 1))}
+       }
+       fv := MakeFunc(TypeOf(fn), incr)
+       ValueOf(&fn).Elem().Set(fv)
+       if r := fn(2); r != 3 {
+               t.Errorf("Call returned %d, want 3", r)
+       }
+       if r := fv.Call([]Value{ValueOf(14)})[0].Int(); r != 15 {
+               t.Errorf("Call returned %d, want 15", r)
+       }
+       if r := fv.Interface().(func(int) int)(26); r != 27 {
+               t.Errorf("Call returned %d, want 27", r)
+       }
+}
+
 type Point struct {
        x, y int
 }
index ccdd683a0c831ac947a0350cca436cd30bfce1d4..e1608ea6c4aa38562a9a076c27453b4391671962 100644 (file)
@@ -22,7 +22,7 @@ type makeFuncImpl struct {
 // that wraps the function fn. When called, that new function
 // does the following:
 //
-//     - converts its arguments to a list of Values args.
+//     - converts its arguments to a slice of Values.
 //     - runs results := fn(args).
 //     - returns the results as a slice of Values, one per formal result.
 //