1
0
mirror of https://github.com/golang/go synced 2024-11-18 13:04:46 -07:00

stringer: don't emit unnecessary variables

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>
This commit is contained in:
HENRY-PC\Henry 2017-12-06 22:54:56 +07:00 committed by Rob Pike
parent 04447353bc
commit 71657689f0
2 changed files with 10 additions and 6 deletions

View File

@ -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 {

View File

@ -487,7 +487,9 @@ 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")
@ -495,11 +497,14 @@ func (g *Generator) declareIndexAndNameVars(runs [][]Value, typeName string) {
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