]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
reflect: Fix calling Interface method on value created by MakeFunc.
authorIan Lance Taylor <ian@gcc.gnu.org>
Fri, 4 Oct 2013 18:52:22 +0000 (18:52 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Fri, 4 Oct 2013 18:52:22 +0000 (18:52 +0000)
From-SVN: r203212

libgo/go/reflect/all_test.go
libgo/go/reflect/makefunc.go

index 140a068b9cae32640d8290c043d415234da04fd3..526f09bb2ca1acaaa19f333aeb4a7712bfc8df63 100644 (file)
@@ -1454,6 +1454,30 @@ func TestMakeFunc(t *testing.T) {
        }
 }
 
+func TestMakeFuncInterface(t *testing.T) {
+       switch runtime.GOARCH {
+       case "amd64", "386":
+       default:
+               t.Skip("MakeFunc not implemented for " + runtime.GOARCH)
+       }
+
+       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 3e0a79258e6b7698d6c741532397740127599e37..3e8085bec65d81839e14fc6ad4b52db2371cc20c 100644 (file)
@@ -63,7 +63,7 @@ func MakeFunc(typ Type, fn func(args []Value) (results []Value)) Value {
 
        impl := &makeFuncImpl{code: code, typ: ftyp, fn: fn}
 
-       return Value{t, unsafe.Pointer(impl), flag(Func) << flagKindShift}
+       return Value{t, unsafe.Pointer(&impl), flag(Func<<flagKindShift) | flagIndir}
 }
 
 // makeFuncStub is an assembly function that is the code half of