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
go/printer: formats anonymous interfaces and structs differently. #7004
Labels
Milestone
Comments
Labels changed: added release-none, repo-main. Owner changed to @griesemer. Status changed to Accepted. |
My thoughts on the options: a) Do nothing: fine with me. b) Change struct to expand: prefer not. c) Change small interfaces to inline: very slighty positive. Sometimes people write: if f, ok := x.(interface { Foo() }); ok { f.Foo() } Which is always rewritten as: if f, ok := x.(interface { Foo() }); ok { f.Foo() } Which means you end up writing: type fooer interface { Foo() } if f, ok := x.(fooer); ok { f.Foo() } |
C) is not an option, in the sense that we never shorten things this way. The missing option is D) preserve single-line single-method interfaces That is, type T1 struct{ F } type T2 interface { M() } type T3 struct { F } type T4 interface { M() } T3 and T4 must be left alone no matter what. Today, T1 is left alone as well, but T2 is changed. I don't mind if we modify gofmt to allow T2 (but not to turn T4 into T2). I've run into the example Brad gave too. I'm also okay with leaving things alone. Robert should decide. |
This was fixed in Go 1.10 |
Thanks, closing. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The text was updated successfully, but these errors were encountered: