diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2013-10-04 18:52:22 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2013-10-04 18:52:22 +0000 |
commit | 8a2cb59f1c4a4822f727a5cd8fdfc7d87636508e (patch) | |
tree | 8959671884352d02a3071c84bdd700af6043564d /libgo/go/reflect | |
parent | c6d2bfbb441ed464ed61e0ee7045c77cf4a94b06 (diff) | |
download | gcc-8a2cb59f1c4a4822f727a5cd8fdfc7d87636508e.zip gcc-8a2cb59f1c4a4822f727a5cd8fdfc7d87636508e.tar.gz gcc-8a2cb59f1c4a4822f727a5cd8fdfc7d87636508e.tar.bz2 |
reflect: Fix calling Interface method on value created by MakeFunc.
From-SVN: r203212
Diffstat (limited to 'libgo/go/reflect')
-rw-r--r-- | libgo/go/reflect/all_test.go | 24 | ||||
-rw-r--r-- | libgo/go/reflect/makefunc.go | 2 |
2 files changed, 25 insertions, 1 deletions
diff --git a/libgo/go/reflect/all_test.go b/libgo/go/reflect/all_test.go index 140a068..526f09b 100644 --- a/libgo/go/reflect/all_test.go +++ b/libgo/go/reflect/all_test.go @@ -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 } diff --git a/libgo/go/reflect/makefunc.go b/libgo/go/reflect/makefunc.go index 3e0a792..3e8085b 100644 --- a/libgo/go/reflect/makefunc.go +++ b/libgo/go/reflect/makefunc.go @@ -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 |