aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Gerrand <adg@golang.org>2011-09-08 10:52:28 +1000
committerAndrew Gerrand <adg@golang.org>2011-09-08 10:52:28 +1000
commit616801951bd8ed946acc70ea80c1d1c8e29c03b8 (patch)
treedd5d733af8606b61072b0ffacea536c30d2dcc51
parente84d4effa1f80c526ac4f5462038d94a050443b1 (diff)
downloadgo-616801951bd8ed946acc70ea80c1d1c8e29c03b8.tar.gz
go-616801951bd8ed946acc70ea80c1d1c8e29c03b8.zip
[release-branch.r60] gofix: do not convert url in field names
««« CL 4972052 / 0f7a647510f9 gofix: do not convert url in field names There's some ambiguity in the U{url: url} case as it could be both a map or a struct literal, but given context it's more likely a struct, so U{url: url_} rather than U{url_: url_}. At least that was the case for me. R=golang-dev, rsc, adg CC=golang-dev https://golang.org/cl/4972052 »»» R=golang-dev, dsymonds CC=golang-dev https://golang.org/cl/4962058
-rw-r--r--src/cmd/gofix/url.go13
-rw-r--r--src/cmd/gofix/url_test.go10
2 files changed, 22 insertions, 1 deletions
diff --git a/src/cmd/gofix/url.go b/src/cmd/gofix/url.go
index f12868dd8e..7135d8edf1 100644
--- a/src/cmd/gofix/url.go
+++ b/src/cmd/gofix/url.go
@@ -46,7 +46,12 @@ func url(f *ast.File) bool {
fixed := false
// Update URL code.
+ var skip interface{}
urlWalk := func(n interface{}) {
+ if n == skip {
+ skip = nil
+ return
+ }
// Is it an identifier?
if ident, ok := n.(*ast.Ident); ok && ident.Name == "url" {
ident.Name = "url_"
@@ -57,6 +62,12 @@ func url(f *ast.File) bool {
fixed = urlDoFields(fn.Params) || fixed
fixed = urlDoFields(fn.Results) || fixed
}
+ // U{url: ...} is likely a struct field.
+ if kv, ok := n.(*ast.KeyValueExpr); ok {
+ if ident, ok := kv.Key.(*ast.Ident); ok && ident.Name == "url" {
+ skip = ident
+ }
+ }
}
// Fix up URL code and add import, at most once.
@@ -64,7 +75,7 @@ func url(f *ast.File) bool {
if fixed {
return
}
- walk(f, urlWalk)
+ walkBeforeAfter(f, urlWalk, nop)
addImport(f, "url")
fixed = true
}
diff --git a/src/cmd/gofix/url_test.go b/src/cmd/gofix/url_test.go
index d6e3b52ddf..8d9542cbca 100644
--- a/src/cmd/gofix/url_test.go
+++ b/src/cmd/gofix/url_test.go
@@ -80,10 +80,15 @@ import (
"http"
)
+type U struct{ url int }
+type M map[int]int
+
func f() {
http.ParseURL(a)
var url = 23
url, x := 45, y
+ _ = U{url: url}
+ _ = M{url + 1: url}
}
func g(url string) string {
@@ -98,10 +103,15 @@ func h() (url string) {
import "url"
+type U struct{ url int }
+type M map[int]int
+
func f() {
url.Parse(a)
var url_ = 23
url_, x := 45, y
+ _ = U{url: url_}
+ _ = M{url_ + 1: url_}
}
func g(url_ string) string {