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
Milestone

Comments

@willfaught
Copy link
Contributor

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

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.

@ghost
Copy link

ghost commented Sep 20, 2017

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

@jimmyfrasche
Copy link
Member

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

@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

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
Development

No branches or pull requests

5 participants