Hacker News new | past | comments | ask | show | jobs | submit login

I managed to track down the original code containing these snippets using the GitHub code search tool:

https://github.com/adobe/kratos/blob/93246f92d53feba73743dbf...

https://github.com/StalkR/goircbot/blob/6081ed5d1d74f01767d7...

The difference is that in one case, informer is an interface, so the method call resolves informer.Run immediately and there's no issue. In the other case, a is a struct Alarm, and gets copied by value, and the Monitor method takes a pointer receiver. So my original intuition was right, the compiler is essentially translating

    go a.Monitor(b)
into

    go (&a).Monitor(b)
Which has a reference to the loop variable, and creates an issue.



Cf. https://www.youtube.com/watch?v=0m6iFd9N_CY which features this code:

    func soldAnother(a *album) {
    a.copies++ // note the pointer. Can use dot notation on pointer,
    // equivalent to (*a).copies++)




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: