From: Matthew Dempsky Date: Tue, 7 Feb 2017 23:29:18 +0000 (-0800) Subject: cmd/gofmt: clear pattern match map at the correct time X-Git-Tag: go1.9beta1~1682 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=e410d2a81ef26d7dcef0c712b584d2345b15148e;p=gostls13.git 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 Reviewed-by: Robert Griesemer TryBot-Result: Gobot Gobot --- 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