-
Notifications
You must be signed in to change notification settings - Fork 18k
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
fmt: priority of error and Stringer when handling non-simple types #34464
Comments
I think this is very similar to the previously discussed and closed #25707. Looks to be working as documented currently (https://golang.org/pkg/fmt/) and we would not be able to change it without breaking backwards compatibility.
If it is agreed to be working as documented for fmt do you want your report to be considered as a change proposal? You could if wanted rewrite it a bit before to put more focus in the proposal on why the new way would better and worth potentially breaking existing code that should be rewritten. Maybe add more information by searching codebases github how often this problem can be seen in existing code and what the workarounds developed are that would be avoided or new ones needed to be added. |
Thanks for the report. This is working as documented and intended, so closing. |
@gopherbot, please remove WaitingForInfo |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes (and on playground)
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Reproducible on playground here: https://play.golang.org/p/y4VFIJEgqOs
What did you expect to see?
I'd expect to see the priority of the type switch here to be reversed.
I.e., the first check should be "does it satisfy
Stringer
", followed "does it satisfyerror
"Either way it'll lead to a panic when used as an embedded field, but, more often than not users will check errors before using them so making
Stringer
of higher priority would make the most common use-case the correct one.There might be a reason to have
error
checked first, but it's not immediately obvious here.The text was updated successfully, but these errors were encountered: