aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuuk van Dijk <lvd@golang.org>2012-02-06 16:38:59 +0100
committerLuuk van Dijk <lvd@golang.org>2012-02-06 16:38:59 +0100
commit0b9f0908610bc1d3938a0cb6d33dbfb4c1e9c954 (patch)
treee0b6563d24e632b7408aa123143a85e739a06b5b
parent5efd5624cc5b22f50d2739b0f1dbce32402206cb (diff)
downloadgo-0b9f0908610bc1d3938a0cb6d33dbfb4c1e9c954.tar.gz
go-0b9f0908610bc1d3938a0cb6d33dbfb4c1e9c954.zip
cmd/gc: another special (%hhS) case for method names.
Fixes #2877 R=rsc CC=golang-dev https://golang.org/cl/5637047
-rw-r--r--src/cmd/gc/fmt.c10
-rw-r--r--test/fixedbugs/bug407.dir/one.go20
-rw-r--r--test/fixedbugs/bug407.dir/two.go15
-rw-r--r--test/fixedbugs/bug407.go7
4 files changed, 52 insertions, 0 deletions
diff --git a/src/cmd/gc/fmt.c b/src/cmd/gc/fmt.c
index 35d33bce87..5437dac1db 100644
--- a/src/cmd/gc/fmt.c
+++ b/src/cmd/gc/fmt.c
@@ -1097,6 +1097,16 @@ exprfmt(Fmt *f, Node *n, int prec)
return fmtprint(f, "%V", &n->val);
case ONAME:
+ // Special case: explicit name of func (*T) method(...) is turned into pkg.(*T).method,
+ // but for export, this should be rendered as (*pkg.T).meth.
+ // These nodes have the special property that they are names with a left OTYPE and a right ONAME.
+ if(fmtmode == FExp && n->left && n->left->op == OTYPE && n->right && n->right->op == ONAME) {
+ if(isptr[n->left->type->etype])
+ return fmtprint(f, "(%T).%hhS", n->left->type, n->right->sym);
+ else
+ return fmtprint(f, "%T.%hhS", n->left->type, n->right->sym);
+ }
+ //fallthrough
case OPACK:
case ONONAME:
return fmtprint(f, "%S", n->sym);
diff --git a/test/fixedbugs/bug407.dir/one.go b/test/fixedbugs/bug407.dir/one.go
new file mode 100644
index 0000000000..a91d904333
--- /dev/null
+++ b/test/fixedbugs/bug407.dir/one.go
@@ -0,0 +1,20 @@
+// Copyright 2012 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package one
+
+// Issue 2877
+type T struct {
+ f func(t *T, arg int)
+ g func(t T, arg int)
+}
+
+func (t *T) foo(arg int) {}
+func (t T) goo(arg int) {}
+
+func (t *T) F() { t.f = (*T).foo }
+func (t *T) G() { t.g = T.goo }
+
+
+
diff --git a/test/fixedbugs/bug407.dir/two.go b/test/fixedbugs/bug407.dir/two.go
new file mode 100644
index 0000000000..67e1852ea0
--- /dev/null
+++ b/test/fixedbugs/bug407.dir/two.go
@@ -0,0 +1,15 @@
+// Copyright 2012 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Use the functions in one.go so that the inlined
+// forms get type-checked.
+
+package two
+
+import "./one"
+
+func use() {
+ var r one.T
+ r.F()
+}
diff --git a/test/fixedbugs/bug407.go b/test/fixedbugs/bug407.go
new file mode 100644
index 0000000000..50af6006fb
--- /dev/null
+++ b/test/fixedbugs/bug407.go
@@ -0,0 +1,7 @@
+// $G $D/$F.dir/one.go && $G $D/$F.dir/two.go
+
+// Copyright 2011 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package ignored