From daf64bf567354167aa0f60a7e4688892e55825dd Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Fri, 24 Sep 2010 12:58:08 -0700 Subject: [PATCH] gofmt: don't substitute invalid positions with valid ones in rewrites Fixes rewrite bug: 'f(x) -> f(0)' where functions "picked up" ... arguments. R=rsc CC=golang-dev https://golang.org/cl/2279041 --- src/cmd/gofmt/rewrite.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/cmd/gofmt/rewrite.go b/src/cmd/gofmt/rewrite.go index 3aaaebdd1a..6170a64f4d 100644 --- a/src/cmd/gofmt/rewrite.go +++ b/src/cmd/gofmt/rewrite.go @@ -203,6 +203,10 @@ func subst(m map[string]reflect.Value, pattern reflect.Value, pos reflect.Value) } if pos != nil && pattern.Type() == positionType { + // use new position only if old position was valid in the first place + if old := pattern.Interface().(token.Position); !old.IsValid() { + return pattern + } return pos } -- 2.48.1