aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2011-01-07 13:33:29 -0800
committerRobert Griesemer <gri@golang.org>2011-01-07 13:33:29 -0800
commit9d634e50c7d9a132897805a8604e15ce7db3de7b (patch)
tree1bbba1ee9861b9a44a18dea2a5ff2de78c75847c
parentee58cc799e42d32e5991ba43390c8fc4778b0c7c (diff)
downloadgo-9d634e50c7d9a132897805a8604e15ce7db3de7b.tar.gz
go-9d634e50c7d9a132897805a8604e15ce7db3de7b.zip
gofmt: rewriter matches apply to expressions only
Fixes #1384. R=rsc CC=golang-dev https://golang.org/cl/3912041
-rw-r--r--src/cmd/gofmt/rewrite.go15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/cmd/gofmt/rewrite.go b/src/cmd/gofmt/rewrite.go
index 7fa8c909a9..a87dbeb8cd 100644
--- a/src/cmd/gofmt/rewrite.go
+++ b/src/cmd/gofmt/rewrite.go
@@ -111,15 +111,18 @@ func match(m map[string]reflect.Value, pattern, val reflect.Value) bool {
if m != nil && pattern.Type() == identType {
name := pattern.Interface().(*ast.Ident).Name
if isWildcard(name) {
- if old, ok := m[name]; ok {
- return match(nil, old, val)
+ // wildcards only match expressions
+ if _, ok := val.Interface().(ast.Expr); ok {
+ if old, ok := m[name]; ok {
+ return match(nil, old, val)
+ }
+ m[name] = val
+ return true
}
- m[name] = val
- return true
}
}
- // Otherwise, the expressions must match recursively.
+ // Otherwise, pattern and val must match recursively.
if pattern == nil || val == nil {
return pattern == nil && val == nil
}
@@ -204,7 +207,7 @@ 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() {
+ if old := pattern.Interface().(token.Pos); !old.IsValid() {
return pattern
}
return pos