summaryrefslogtreecommitdiff
path: root/libgo/go
diff options
context:
space:
mode:
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2013-11-19 02:30:03 +0000
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2013-11-19 02:30:03 +0000
commit723f3d2c0e968a337e990bdcacf57fa5650750f6 (patch)
tree16f6d5875810d941d00dcc7096e6e77ae76ce1bf /libgo/go
parenta3db0683aede5b937aa7a76bb4a0f547deed7144 (diff)
downloadgcc-723f3d2c0e968a337e990bdcacf57fa5650750f6.tar.gz
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 git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@205001 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo/go')
-rw-r--r--libgo/go/reflect/all_test.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/libgo/go/reflect/all_test.go b/libgo/go/reflect/all_test.go
index 6ab02f7d854..918adce887f 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":