diff options
author | gVisor bot <gvisor-bot@google.com> | 2020-09-23 07:27:30 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-09-23 07:29:31 -0700 |
commit | d00207ff482fd5cfa607d37979b5455f41a86e3b (patch) | |
tree | 618b977ecaa896174e32c445cda99efac23e1f1f /tools/go_generics/go_merge | |
parent | 99decaadd6da0df2d8ec70ddea9d754c9d71a584 (diff) |
Internal change.
PiperOrigin-RevId: 333287864
Diffstat (limited to 'tools/go_generics/go_merge')
-rw-r--r-- | tools/go_generics/go_merge/main.go | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/tools/go_generics/go_merge/main.go b/tools/go_generics/go_merge/main.go index f6a331123..e0345500f 100644 --- a/tools/go_generics/go_merge/main.go +++ b/tools/go_generics/go_merge/main.go @@ -77,6 +77,7 @@ func main() { // Create a new declaration slice with all imports at the top, merging any // redundant imports. imports := make(map[string]*ast.ImportSpec) + var importNames []string // Keep imports in the original order to get deterministic output. var anonImports []*ast.ImportSpec for _, d := range f.Decls { if g, ok := d.(*ast.GenDecl); ok && g.Tok == token.IMPORT { @@ -98,6 +99,7 @@ func main() { } } else { imports[n] = i + importNames = append(importNames, n) } } } @@ -112,8 +114,8 @@ func main() { Lparen: token.NoPos + 1, Specs: make([]ast.Spec, 0, l), } - for _, i := range imports { - d.Specs = append(d.Specs, i) + for _, i := range importNames { + d.Specs = append(d.Specs, imports[i]) } for _, i := range anonImports { d.Specs = append(d.Specs, i) |