Skip to content

Commit

Permalink
stringer: don't emit unnecessary variables
Browse files Browse the repository at this point in the history
Fixes golang/go#23014

Change-Id: I159f83bae0ed632b0b3c00f8ab02f5701acbc4cc
Reviewed-on: https://go-review.googlesource.com/82215
Run-TryBot: Rob Pike <r@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
  • Loading branch information
henryas authored and robpike committed Dec 7, 2017
1 parent 7528663 commit 822dabd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
1 change: 0 additions & 1 deletion golden_test.go
Expand Up @@ -110,7 +110,6 @@ const (
var (
_Gap_index_0 = [...]uint8{0, 3, 8}
_Gap_index_1 = [...]uint8{0, 4, 7, 12, 17, 21}
_Gap_index_2 = [...]uint8{0, 6}
)
func (i Gap) String() string {
Expand Down
15 changes: 10 additions & 5 deletions stringer.go
Expand Up @@ -487,19 +487,24 @@ func (g *Generator) declareIndexAndNameVars(runs [][]Value, typeName string) {
var indexes, names []string
for i, run := range runs {
index, name := g.createIndexAndNameDecl(run, typeName, fmt.Sprintf("_%d", i))
indexes = append(indexes, index)
if len(run) != 1 {
indexes = append(indexes, index)
}
names = append(names, name)
}
g.Printf("const (\n")
for _, name := range names {
g.Printf("\t%s\n", name)
}
g.Printf(")\n\n")
g.Printf("var (")
for _, index := range indexes {
g.Printf("\t%s\n", index)

if len(indexes) > 0 {
g.Printf("var (")
for _, index := range indexes {
g.Printf("\t%s\n", index)
}
g.Printf(")\n\n")
}
g.Printf(")\n\n")
}

// declareIndexAndNameVar is the single-run version of declareIndexAndNameVars
Expand Down

0 comments on commit 822dabd

Please sign in to comment.