1
0
mirror of https://github.com/golang/go synced 2024-11-25 07:57:56 -07:00

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
This commit is contained in:
Robert Griesemer 2010-09-24 12:58:08 -07:00
parent 5c4917ce33
commit daf64bf567

View 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
}