-
Notifications
You must be signed in to change notification settings - Fork 18.1k
cmd/{godoc,vet},testing: godoc disagrees with the docs and vet about validity of example name suffixes #27442
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
Comments
The title of the issue suggests that the issue is with godoc. But it seems you want the documented behavior itself to allow numeric characters. In which case, this should be a proposal issue because what you are suggesting is a behavior change. I think allowing numerical characters deviates from our existing language spec, which forces all identifiers to start with a letter (https://tip.golang.org/ref/spec#identifier). IMO, we should fix godoc to be consistent with the docs and with vet. According to current behavior, godoc should just ignore any examples which do not match the example name rule. |
The formulation of the bug is what it is because there are three moving parts here, the testing package documentation, the current godoc behaviour and the current vet behaviour; maybe the prefix should be "cmd/{godoc,vet},testing:". I don't agree that the spec comes into play in this (with a caveat below) as the suffix is not a language-level identifier, it's essentially a human-directed comment hidden in an identifier. Where the spec does come in is that the suffix must not be interpretable as an exported method since then godoc would attempt and fail to find a place to put it or would place it in the wrong location. Interestingly, vet does not have a problem with the M part of a types example test pointing to an exported field, although that will not ever be rendered. So, the issue is complicated, but could be simple. But, it seems to me that a proposal is more complicated than is warranted here. |
The problem is that the example syntax is fundamentally ambiguous and ideally all the tools should be consistent about how they resolve that ambiguity (although there is technically no ambiguity in this specific case due to the leading digit). Unfortunately, currently each tool has their own copy of the example parsing logic, and handles this case differently. I brought up this issue in #23864. Having a unified implementation of example parsing should resolve this problem. Perhaps we close this as a duplicate of that one? |
I'm happy for this to be closed and subsumed into that. What I would like to be considered though is the rule mentioned above; it does not need to be a lowercase initial, it just needs to not be an uppercase initial. |
The challenge is that the logic for |
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
)?linux/amd64
What did you do?
However, godoc renders the 2sat example.
What did you expect to see?
An error from vet and a failure from godoc to render the example.
What did you see instead?
A vet error but a rendered example.
What would you like to see?
No error and a rendered example. That is, a relaxation of the documented requirement for an initial lowercase letter in the suffix ("The suffix must start with a lower-case letter.") to allow numeric leading glyphs.
The text was updated successfully, but these errors were encountered: