]> Cypherpunks repositories - gostls13.git/commitdiff
gofmt: don't substitute invalid positions with valid ones in rewrites
authorRobert Griesemer <gri@golang.org>
Fri, 24 Sep 2010 19:58:08 +0000 (12:58 -0700)
committerRobert Griesemer <gri@golang.org>
Fri, 24 Sep 2010 19:58:08 +0000 (12:58 -0700)
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

index 3aaaebdd1a14e0079b80de15d6aac95cecdfdcfd..6170a64f4dc5810def3cc2be35cda0a1d99aa09b 100644 (file)
@@ -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
        }