reflect: test using a MakeFunc value in a couple of different ways

The gccgo implementation mishandled calling Interface on a
value created by MakeFunc.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/14401043
This commit is contained in:
Ian Lance Taylor 2013-10-04 13:12:50 -07:00
parent eb002c50f5
commit ef4e12a4ba
2 changed files with 19 additions and 1 deletions

View 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
}