Skip to content

Commit

Permalink
protoc-gen-go: format interfaces for gofmt 1.9 and 1.10 (#486)
Browse files Browse the repository at this point in the history
Change the pre-gofmt generated code for oneof discriminant interfaces
from:
	type T interface { T() }
to:
	type T interface {
		T()
	}

Prior to Go 1.9, gofmt rewrote the single-line form into the multi-line
one. Go 1.10 and later preserve the single-line form for single-method
interfaces. Generating code that is handled identically by both versions
of gofmt avoids spurious diffs with golden test data.

Change-Id: Ibb229827823a50e963bcd1b34e59a286654b415f
  • Loading branch information
neild authored and dsnet committed Jan 18, 2018
1 parent 7d76aa1 commit 2bd7280
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion protoc-gen-go/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2174,7 +2174,11 @@ func (g *Generator) generateMessage(message *Descriptor) {
// TODO: Revisit this and consider reverting back to anonymous interfaces.
for oi := range message.OneofDecl {
dname := oneofDisc[int32(oi)]
g.P("type ", dname, " interface { ", dname, "() }")
g.P("type ", dname, " interface {")
g.In()
g.P(dname, "()")
g.Out()
g.P("}")
}
g.P()
for i, field := range message.Field {
Expand Down

0 comments on commit 2bd7280

Please sign in to comment.