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

cmd/gofmt: one-method interfaces should be able to be on one line #21952

Closed
willfaught opened this issue Sep 20, 2017 · 5 comments
Closed

cmd/gofmt: one-method interfaces should be able to be on one line #21952

willfaught opened this issue Sep 20, 2017 · 5 comments
Assignees
Milestone

Comments

@willfaught
Copy link
Contributor

@willfaught willfaught commented Sep 20, 2017

Like structs.

What did you do?

  1. Go to: https://play.golang.org/p/kA2p7gF5GM
  2. Click Format.

What did you expect to see?

Formatting doesn't change anything.

What did you see instead?

Formatting changes the non-empty interface to span multiple lines.

System details

go version go1.9 darwin/amd64
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/willfaught/Developer/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.9/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.9/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/_1/ggvd2t1x7hz_185crsb36zlr0000gp/T/go-build773933572=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOROOT/bin/go version: go version go1.9 darwin/amd64
GOROOT/bin/go tool compile -V: compile version go1.9
uname -v: Darwin Kernel Version 16.7.0: Thu Jun 15 17:36:27 PDT 2017; root:xnu-3789.70.16~2/RELEASE_X86_64
ProductName:	Mac OS X
ProductVersion:	10.12.6
BuildVersion:	16G29
lldb --version: lldb-370.0.42
  Swift-3.1
@mdempsky
Copy link
Member

@mdempsky mdempsky commented Sep 20, 2017

This would be a backwards compatible change, and personally I'd be happy to see this happen.

But gofmt's formatting is pretty stable nowadays, so perhaps not.

@bontibon
Copy link
Contributor

@bontibon bontibon commented Sep 20, 2017

Another issue: notice how the output changes again if format is clicked a second time.

@jimmyfrasche
Copy link
Member

@jimmyfrasche jimmyfrasche commented Sep 20, 2017

I hate to complain about gofmt but this is the one thing that bugs me about it.

It comes up for me whenever I'm doing type assertions to another interface.

I want to write

if tmp, ok := err.(interface{ Temporary() bool }); ok { //etc

The workaround isn't hard, but I end up with code like

type temporary interface {
  Temporary() bool
}
if tmp, ok := err.(temporary); ok { //etc

which adds more steps to reading the line than I feel should be necessary for a common operation.

@mdempsky
Copy link
Member

@mdempsky mdempsky commented Sep 20, 2017

@bontibon Thanks for pointing that out. I think it's definitely a bug if cmd/gofmt is non-idempotent.

@griesemer griesemer added this to the Go1.10 milestone Sep 20, 2017
@gopherbot
Copy link

@gopherbot gopherbot commented Sep 26, 2017

Change https://golang.org/cl/66130 mentions this issue: go/printer: allow one-method interfaces to be printed on a single line

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants
You can’t perform that action at this time.