diff options
author | Matthew Dempsky <mdempsky@google.com> | 2017-02-07 15:29:18 -0800 |
---|---|---|
committer | Matthew Dempsky <mdempsky@google.com> | 2017-02-08 04:48:20 +0000 |
commit | e410d2a81ef26d7dcef0c712b584d2345b15148e (patch) | |
tree | 1c334676022664d04143c8bcb813e10a9902ef3d /src/cmd/gofmt | |
parent | 87ad863f359de3760578acb7f7a4d7e333c9cdc8 (diff) | |
download | go-e410d2a81ef26d7dcef0c712b584d2345b15148e.tar.gz go-e410d2a81ef26d7dcef0c712b584d2345b15148e.zip |
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>
Diffstat (limited to 'src/cmd/gofmt')
-rw-r--r-- | src/cmd/gofmt/rewrite.go | 2 | ||||
-rw-r--r-- | src/cmd/gofmt/testdata/rewrite9.golden | 11 | ||||
-rw-r--r-- | src/cmd/gofmt/testdata/rewrite9.input | 11 |
3 files changed, 23 insertions, 1 deletions
diff --git a/src/cmd/gofmt/rewrite.go b/src/cmd/gofmt/rewrite.go index 550492bf29..79b7858a5a 100644 --- a/src/cmd/gofmt/rewrite.go +++ b/src/cmd/gofmt/rewrite.go @@ -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())) } diff --git a/src/cmd/gofmt/testdata/rewrite9.golden b/src/cmd/gofmt/testdata/rewrite9.golden new file mode 100644 index 0000000000..fffbd3d05b --- /dev/null +++ b/src/cmd/gofmt/testdata/rewrite9.golden @@ -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 diff --git a/src/cmd/gofmt/testdata/rewrite9.input b/src/cmd/gofmt/testdata/rewrite9.input new file mode 100644 index 0000000000..106ad94bc5 --- /dev/null +++ b/src/cmd/gofmt/testdata/rewrite9.input @@ -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 |