1
0
mirror of https://github.com/golang/go synced 2024-11-24 04:10:14 -07:00

cmd/gofmt: clear pattern match map at the correct time

We need to clear the pattern match map after the recursive rewrite
applications, otherwise there might be lingering entries that cause
match to fail.

Fixes #18987.

Change-Id: I7913951c455c98932bda790861db6a860ebad032
Reviewed-on: https://go-review.googlesource.com/36546
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Matthew Dempsky 2017-02-07 15:29:18 -08:00
parent 87ad863f35
commit e410d2a81e
3 changed files with 23 additions and 1 deletions

View File

@ -66,10 +66,10 @@ func rewriteFile(pattern, replace ast.Expr, p *ast.File) *ast.File {
if !val.IsValid() {
return reflect.Value{}
}
val = apply(rewriteVal, val)
for k := range m {
delete(m, k)
}
val = apply(rewriteVal, val)
if match(m, pat, val) {
val = subst(m, repl, reflect.ValueOf(val.Interface().(ast.Node).Pos()))
}

11
src/cmd/gofmt/testdata/rewrite9.golden vendored Normal file
View File

@ -0,0 +1,11 @@
//gofmt -r=a&&b!=2->a
// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Issue 18987.
package p
const _ = x != 1

11
src/cmd/gofmt/testdata/rewrite9.input vendored Normal file
View File

@ -0,0 +1,11 @@
//gofmt -r=a&&b!=2->a
// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Issue 18987.
package p
const _ = x != 1 && x != 2