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

gofmt: rewriter matches apply to expressions only

Fixes #1384.

R=rsc
CC=golang-dev
https://golang.org/cl/3912041
This commit is contained in:
Robert Griesemer 2011-01-07 13:33:29 -08:00
parent ee58cc799e
commit 9d634e50c7

View File

@ -111,6 +111,8 @@ 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) {
// wildcards only match expressions
if _, ok := val.Interface().(ast.Expr); ok {
if old, ok := m[name]; ok {
return match(nil, old, val)
}
@ -118,8 +120,9 @@ func match(m map[string]reflect.Value, pattern, val reflect.Value) bool {
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