New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/go: Allow empty go files #37152
Comments
This change would require changing the language specification as well as multiple build systems, libraries for processing Go code, and existing tooling that expects to find package declarations in Go files. That seems vastly out of proportion for something that can be better solved by adding a |
I agree with Dominik. Even if we agreed this is a good idea, it would take a few painful years for all the tooling and libraries out there to catch up. This proposal is also not complete, in my opinion. What's an empty Go file? It's really not a file containing zero bytes, as you yourself mention that it can have comments. Would those comments be Go syntax? Would build directives in such files be obeyed, like |
"A file with no package declaration and no code to compile" then. The compiler can already detect this. My proposal was simply to ignore this case and throw it away rather than complaining and stopping compilation.
Of course. If you comment out the whole file, you'll get
Neither. You'd get an AST of a bunch of comments (unless the parser throws them out?). |
Given the trivial Can you give more detail on the motivating use-case? In my experience most packages don't even compile if you comment out an entire non-test source file, and the |
Timed out in state WaitingForInfo. Closing. (I am just a bot, though. Please speak up if this is a mistake or you have the requested information.) |
When isolating tests, it's convenient to be able to just comment out entire source files by typing
CTRL-a
,CTRL-/
. However, if you do that in a go source file, the compiler complains:What would be nicer would be to have the go compiler simply ignore empty go files, so that we don't have to go back to the top of the file and uncomment that one package line just to keep it happy.
The end result is the same either way: A compilation unit that does nothing.
The text was updated successfully, but these errors were encountered: