Hi Marc, thanks for your comment:
>
The thing is, if you try to cover this for a mistake, then we can cover every mistake, right?
Not at all. I think the idea is to try to catch at compile-time common mistakes, that are easily made, can be missed during testing and can have serious consequences. There have been numerous additions to the language for this reason and many other proposals some of which will probably be implemented in Go2 (eg
https://github.com/golang/go/issues/20733 which I also thought of).
I guess it comes down to an assessment of how common this is, seriousness etc. I couldn't find a discussion of this anywhere but in my experience it is a very common problem for beginners but something we experienced Gophers forget about.
>
There is probably a linter which can check this, or you can write a linter yourself.
This is not a general solution for the millions of beginner Go programmers. Moreover, most do not run linters or even know what is available. And really the only Go "linter" (in the sense I think you mean) should be go vet. (Golint is more about style guidelines. Other linters that people have written have good ideas but should be added to the official tools - go vet of better the compiler - to be useful.)
It would be a (small) step if go vet detected the problem but many don't use go vet. My understanding of the unofficial current strategy for handling dubious code is:
1. "go vet" to report the problem if it's possible that the code could be correct AND there is no simple workaround to avoid it
2. compiler error is there is dubious code that could be clarified with a simple code change (like type cast)
Thanks again for the feedback. It has helped me clarify what I want to say in the proposal.