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
x/tools/gopls: missing error diagnostics for "missing function body" #64089
Comments
The current behavior is correct (or rather, it's the best we can do). Per the spec, function bodies are optional in go code. The way I think of it is: it's not an error until you try to link, and with Put differently, if we did this there would be thousands of errors in the Go standard library, and IIUC we have no practical way of identifying which missing function bodies are missing by accident. By contrast, generic functions and |
Closing as I don't think we can do anything here. Please correct me if I'm wrong. |
For some definition of "correct" 😄 From the perspective of someone writing a Go program using However, this again comes back to the point of "what am I trying to do with So whilst it might internally be "correct" to not report errors in this situation, I'm not sure I agree that it is "correct" from the perspective of a |
You removed the parenthetical :)! It is "correct" according to the spec, and unfortunate that it's the best we can do. Absent external configuration (such as a build definition), and a lot of additional logic, I don't think there's a way to address this problem. I'd be happy to hear otherwise. |
Gopls, by design, executes only modular (package-at-a-time) analyses in real time, analogous to a compiler. By contrast, whole program analyses such as the linker or govulncheck aren't executed in real time because they need additional external information--such as which main package(s) to operate on---which means their diagnostics are not a function of a package and its transitive closure. As you can imagine, this makes them prohibitively expensive to compute in real time. You can of course request whole-program analyses explicitly, for example by invoking a "run test" code action on Test function, or invoking govulnheck from your go.mod file. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Open
main.go
in a gopls-powered editor.What did you expect to see?
An error diagnostic telling me that
func hello()
is missing a function body. Just like that reported bygo run
:What did you see instead?
No error diagnostic.
cc @findleyr
The text was updated successfully, but these errors were encountered: