{"action":"created","issue":{"url":"https://api.github.com/repos/golang/go/issues/10132","labels_url":"https://api.github.com/repos/golang/go/issues/10132/labels{/name}","comments_url":"https://api.github.com/repos/golang/go/issues/10132/comments","events_url":"https://api.github.com/repos/golang/go/issues/10132/events","html_url":"https://github.com/golang/go/issues/10132","id":60644049,"number":10132,"title":"range & go: pass a pointer to an element of array leads to a different behavior with/out go","user":{"login":"noxiouz","id":664573,"avatar_url":"https://avatars.githubusercontent.com/u/664573?v=3","gravatar_id":"","url":"https://api.github.com/users/noxiouz","html_url":"https://github.com/noxiouz","followers_url":"https://api.github.com/users/noxiouz/followers","following_url":"https://api.github.com/users/noxiouz/following{/other_user}","gists_url":"https://api.github.com/users/noxiouz/gists{/gist_id}","starred_url":"https://api.github.com/users/noxiouz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/noxiouz/subscriptions","organizations_url":"https://api.github.com/users/noxiouz/orgs","repos_url":"https://api.github.com/users/noxiouz/repos","events_url":"https://api.github.com/users/noxiouz/events{/privacy}","received_events_url":"https://api.github.com/users/noxiouz/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-03-11T11:23:11Z","updated_at":"2015-03-11T11:29:11Z","closed_at":"2015-03-11T11:29:11Z","body":"I met a strange behavior while passing elements of array by pointer to a function. It looks like a bug.\r\nYou can find example here:\r\nhttp://play.golang.org/p/e0dDpyCYCG\r\n```go\r\npackage main\r\n\r\nimport (\r\n\t\"fmt\"\r\n\t\"sync\"\r\n)\r\n\r\nvar wg sync.WaitGroup\r\n\r\ntype Item struct {\r\n\tname string\r\n}\r\n\r\nfunc (i *Item) Name() string {\r\n\tdefer wg.Done()\r\n\treturn i.name\r\n}\r\n\r\nfunc Go(t *Item) {\r\n\tfmt.Println(t.Name())\r\n}\r\n\r\nfunc main() {\r\n\tf := make([]Item, 0)\r\n\tf = append(f, Item{\"1\"})\r\n\tf = append(f, Item{\"2\"})\r\n\tf = append(f, Item{\"3\"})\r\n\tfor _, v := range f {\r\n\t\twg.Add(1)\r\n\t\tgo Go(&v)\r\n\t}\r\n\twg.Wait()\r\n```\r\nThis example prints \r\n```\r\n3\r\n3\r\n3\r\n```\r\nIt doesn't look like an expected behavior.\r\nMoreover this example (http://play.golang.org/p/KY4jEgtgGn) (exactly the same, but without ```go```)\r\n```go\r\npackage main\r\n\r\nimport (\r\n\t\"fmt\"\r\n\t\"sync\"\r\n)\r\n\r\nvar wg sync.WaitGroup\r\n\r\ntype Item struct {\r\n\tname string\r\n}\r\n\r\nfunc (i *Item) Name() string {\r\n\tdefer wg.Done()\r\n\treturn i.name\r\n}\r\n\r\nfunc Go(t *Item) {\r\n\tfmt.Println(t.Name())\r\n}\r\n\r\nfunc main() {\r\n\tf := make([]Item, 0)\r\n\tf = append(f, Item{\"1\"})\r\n\tf = append(f, Item{\"2\"})\r\n\tf = append(f, Item{\"3\"})\r\n\tfor _, v := range f {\r\n\t\twg.Add(1)\r\n\t\tGo(&v)\r\n\t}\r\n\twg.Wait()\r\n}\r\n\r\n```\r\nprints\r\n```\r\n1\r\n2\r\n3\r\n```\r\nI checked it on *1.3.3*, *1.4.1*, *1.4.2*"},"comment":{"url":"https://api.github.com/repos/golang/go/issues/comments/78246488","html_url":"https://github.com/golang/go/issues/10132#issuecomment-78246488","issue_url":"https://api.github.com/repos/golang/go/issues/10132","id":78246488,"user":{"login":"minux","id":135652,"avatar_url":"https://avatars.githubusercontent.com/u/135652?v=3","gravatar_id":"","url":"https://api.github.com/users/minux","html_url":"https://github.com/minux","followers_url":"https://api.github.com/users/minux/followers","following_url":"https://api.github.com/users/minux/following{/other_user}","gists_url":"https://api.github.com/users/minux/gists{/gist_id}","starred_url":"https://api.github.com/users/minux/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/minux/subscriptions","organizations_url":"https://api.github.com/users/minux/orgs","repos_url":"https://api.github.com/users/minux/repos","events_url":"https://api.github.com/users/minux/events{/privacy}","received_events_url":"https://api.github.com/users/minux/received_events","type":"User","site_admin":false},"created_at":"2015-03-11T11:29:11Z","updated_at":"2015-03-11T11:29:11Z","body":"http://golang.org/doc/faq#closures_and_goroutines"}}