Skip to content
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

Closed
remyoudompheng opened this issue Dec 22, 2013 · 7 comments
Closed

Comments

@remyoudompheng
Copy link
Contributor

What steps will reproduce the problem?
1. Format:

package main

var S struct{ F string }
var I interface { F() string }

What is the expected output? What do you see instead?

expected:

Either

package main

var S struct{ F string }
var I interface { F() string }

Or:

package main

var S struct{
    F string
}
var I interface {
    F() string
}

but got:

package main

var S struct{ F string }
var I interface {
    F() string
}


Please use labels and text to provide additional information.
@griesemer
Copy link
Contributor

Comment 1:

Labels changed: added release-none, repo-main.

Owner changed to @griesemer.

Status changed to Accepted.

@bradfitz
Copy link
Contributor

Comment 2:

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()
    }

@rsc
Copy link
Contributor

rsc commented Jan 10, 2014

Comment 3:

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.

@ianlancetaylor
Copy link
Contributor

Comment 4:

I vote for preserving existing single line interfaces.

@adg
Copy link
Contributor

adg commented Jan 22, 2014

Comment 5:

Ditto.

@jimmyfrasche
Copy link
Member

This was fixed in Go 1.10

@ianlancetaylor
Copy link
Contributor

Thanks, closing.

@golang golang locked and limited conversation to collaborators Mar 30, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants