Earlier today, I posted about a problem I was having. The problem was very odd because the code compiled for one set of values for GOOS and GOARCH but would complain about so much as a a "go get" using different values of GOOS and GOARCH. In other words, it seemed that whether a program was legal or not was a function of GOOS and GOARCH.
Well, I found the solution. But it raises some interesting questions. So I'm making this new post to discuss it.
The issue turned out to be that within a single package, I defined a type, let us call it "T", in one file and a method where T was the receiver in a different file.
I remember when I first tried this, I was surprised it worked across files. But I liked it because it helped me to keep some things organized. Of course, I assumed that since the compiler accepted it, this construct was allowed.
When I came across this problem with cross compilation, one of the things I tried was to put the method in the same file as the type it was operating on. Magically, the compiler was happy. So then I went through all the relevant sections of the language specification to figure out what was going on. Clearly somewhere there is a bug since the legality of the program depends on environment variables. But in order to report it, I really need to figure out which case is correct and which case isn't.
The problem is, I couldn't find any mention in the specification about a restriction on methods having to be declared in the same file. I looked through every mention of "file" in the specification and there didn't seem to be any mention of methods anywhere. I also looked in the section on method declarations
and it explicitly states "it must be declared in the same package as the method".
So can I correctly assume that it is legal have the type and method in different files within the same package. The specification seems to say that is fine. If so, where do I report this bug (that the compiler complains when doing cross-compilation, which was my original issue)? I didn't see anything about reporting bugs in the FAQ. Do I simply open an issue on Github?
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to