{"action":"opened","issue":{"url":"https://api.github.com/repos/golang/mock/issues/27","repository_url":"https://api.github.com/repos/golang/mock","labels_url":"https://api.github.com/repos/golang/mock/issues/27/labels{/name}","comments_url":"https://api.github.com/repos/golang/mock/issues/27/comments","events_url":"https://api.github.com/repos/golang/mock/issues/27/events","html_url":"https://github.com/golang/mock/issues/27","id":139665432,"number":27,"title":"SetArg on slice silently fails","user":{"login":"Kaedys","id":9020449,"avatar_url":"https://avatars.githubusercontent.com/u/9020449?v=3","gravatar_id":"","url":"https://api.github.com/users/Kaedys","html_url":"https://github.com/Kaedys","followers_url":"https://api.github.com/users/Kaedys/followers","following_url":"https://api.github.com/users/Kaedys/following{/other_user}","gists_url":"https://api.github.com/users/Kaedys/gists{/gist_id}","starred_url":"https://api.github.com/users/Kaedys/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kaedys/subscriptions","organizations_url":"https://api.github.com/users/Kaedys/orgs","repos_url":"https://api.github.com/users/Kaedys/repos","events_url":"https://api.github.com/users/Kaedys/events{/privacy}","received_events_url":"https://api.github.com/users/Kaedys/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-03-09T18:44:10Z","updated_at":"2016-03-09T18:44:10Z","closed_at":null,"body":"When SetArg is used to set a slice argument, it silently fails to set the argument when the call occurs.  This is because setting a slice by reflection cannot be done with a one-shot Set() call.  \r\n\r\nThe diff below adds in support for setting of slices.  A similar method will probably be needed for setting arrays, maps, and possible other types (maybe structs?), though my project doesn't have a need for these, so I didn't investigate their implementation.\r\n\r\n``` diff\r\n--- github.com/golang/mock/gomock/call.go\t2016-03-09 12:34:55.000000000 -0600\r\n+++ github.com/golang/mock/gomock/call.go\t2016-03-09 12:34:56.000000000 -0600\r\n@@ -39,6 +39,13 @@\r\n@@ -212,9 +233,38 @@\r\n \t\t}\r\n \t\taction = func() { c.doFunc.Call(doArgs) }\r\n \t}\r\n\r\n \tfor n, v := range c.setArgs {\r\n-\t\treflect.ValueOf(args[n]).Elem().Set(v)\r\n-\t}\r\n+\t\tswitch reflect.TypeOf(args[n]).Kind() {\r\n+\t\tcase reflect.Slice:\r\n+\t\t\tsetSlice(args[n], v)\r\n+\t\tdefault:\r\n+\t\t\treflect.ValueOf(args[n]).Elem().Set(v)\r\n+\t\t}\r\n+\t}\r\n \r\n \trets = c.rets\r\n \tif rets == nil {\r\n@@ -229,6 +279,15 @@\r\n \treturn\r\n }\r\n \r\n+func setSlice(arg interface{}, v reflect.Value) {\r\n+\targ = reflect.MakeSlice(v.Type(), v.Len(), v.Cap())\r\n+\tav := reflect.ValueOf(arg)\r\n+\tfor i := 0; i < av.Len(); i++ {\r\n+\t\tpi := av.Index(i)\r\n+\t\tpi.Set(v.Index(i))\r\n+\t}\r\n+}\r\n+\r\n func (c *Call) methodType() reflect.Type {\r\n \trecv := reflect.ValueOf(c.receiver)\r\n \tfor i := 0; i < recv.Type().NumMethod(); i++ {\r\n```"}}