diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2013-11-19 02:30:03 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2013-11-19 02:30:03 +0000 |
commit | 41674b9fe4c0beb00ac29c32a2085fa670e863a9 (patch) | |
tree | 16f6d5875810d941d00dcc7096e6e77ae76ce1bf /libgo/go | |
parent | 9d5eec2da6a8ce4e457cb25be2c2a1e60a49f8fb (diff) | |
download | gcc-41674b9fe4c0beb00ac29c32a2085fa670e863a9.zip gcc-41674b9fe4c0beb00ac29c32a2085fa670e863a9.tar.gz gcc-41674b9fe4c0beb00ac29c32a2085fa670e863a9.tar.bz2 |
reflect: Handle calls to functions that take or return empty structs
Fixes issue 6761
This simple change seems to work fine, slightly to my surprise.
This includes the tests I submitted to the main Go repository at
https://codereview.appspot.com/26570046
From-SVN: r205001
Diffstat (limited to 'libgo/go')
-rw-r--r-- | libgo/go/reflect/all_test.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/libgo/go/reflect/all_test.go b/libgo/go/reflect/all_test.go index 6ab02f7..918adce 100644 --- a/libgo/go/reflect/all_test.go +++ b/libgo/go/reflect/all_test.go @@ -1434,6 +1434,46 @@ func TestFunc(t *testing.T) { } } +type emptyStruct struct{} + +type nonEmptyStruct struct { + member int +} + +func returnEmpty() emptyStruct { + return emptyStruct{} +} + +func takesEmpty(e emptyStruct) { +} + +func returnNonEmpty(i int) nonEmptyStruct { + return nonEmptyStruct{member: i} +} + +func takesNonEmpty(n nonEmptyStruct) int { + return n.member +} + +func TestCallWithStruct(t *testing.T) { + r := ValueOf(returnEmpty).Call([]Value{}) + if len(r) != 1 || r[0].Type() != TypeOf(emptyStruct{}) { + t.Errorf("returning empty struct returned %s instead", r) + } + r = ValueOf(takesEmpty).Call([]Value{ValueOf(emptyStruct{})}) + if len(r) != 0 { + t.Errorf("takesEmpty returned values: %s", r) + } + r = ValueOf(returnNonEmpty).Call([]Value{ValueOf(42)}) + if len(r) != 1 || r[0].Type() != TypeOf(nonEmptyStruct{}) || r[0].Field(0).Int() != 42 { + t.Errorf("returnNonEmpty returned %s", r) + } + r = ValueOf(takesNonEmpty).Call([]Value{ValueOf(nonEmptyStruct{member: 42})}) + if len(r) != 1 || r[0].Type() != TypeOf(1) || r[0].Int() != 42 { + t.Errorf("takesNonEmpty returned %s", r) + } +} + func TestMakeFunc(t *testing.T) { switch runtime.GOARCH { case "amd64", "386": |