1
0
mirror of https://github.com/golang/go synced 2024-11-21 20:54:45 -07:00

gc: use more Go-like names for methods

Fixes #991.

R=ken2
CC=golang-dev
https://golang.org/cl/4819049
This commit is contained in:
Russ Cox 2011-07-27 17:56:13 -04:00
parent 112267d55e
commit 1bd4b6371a
3 changed files with 26 additions and 5 deletions

View File

@ -1079,7 +1079,10 @@ methodsym(Sym *nsym, Type *t0, int iface)
if(t0->width < types[tptr]->width) if(t0->width < types[tptr]->width)
suffix = "·i"; suffix = "·i";
} }
p = smprint("%#hT·%s%s", t0, nsym->name, suffix); if(t0->sym == S && isptr[t0->etype])
p = smprint("(%#hT).%s%s", t0, nsym->name, suffix);
else
p = smprint("%#hT.%s%s", t0, nsym->name, suffix);
s = pkglookup(p, s->pkg); s = pkglookup(p, s->pkg);
free(p); free(p);
return s; return s;
@ -1106,14 +1109,17 @@ methodname1(Node *n, Node *t)
char *star; char *star;
char *p; char *p;
star = ""; star = nil;
if(t->op == OIND) { if(t->op == OIND) {
star = "*"; star = "*";
t = t->left; t = t->left;
} }
if(t->sym == S || isblank(n)) if(t->sym == S || isblank(n))
return newname(n->sym); return newname(n->sym);
p = smprint("%s%S·%S", star, t->sym, n->sym); if(star)
p = smprint("(%s%S).%S", star, t->sym, n->sym);
else
p = smprint("%S.%S", t->sym, n->sym);
n = newname(pkglookup(p, t->sym->pkg)); n = newname(pkglookup(p, t->sym->pkg));
free(p); free(p);
return n; return n;

View File

@ -23,7 +23,7 @@ func (t T) method() []byte {
Don't worry much about the base levels, but check the ones in our own package. Don't worry much about the base levels, but check the ones in our own package.
/Users/r/go/src/pkg/runtime/debug/stack_test.go:15 (0x13878) /Users/r/go/src/pkg/runtime/debug/stack_test.go:15 (0x13878)
*T.ptrmethod: return Stack() (*T).ptrmethod: return Stack()
/Users/r/go/src/pkg/runtime/debug/stack_test.go:18 (0x138dd) /Users/r/go/src/pkg/runtime/debug/stack_test.go:18 (0x138dd)
T.method: return t.ptrmethod() T.method: return t.ptrmethod()
/Users/r/go/src/pkg/runtime/debug/stack_test.go:23 (0x13920) /Users/r/go/src/pkg/runtime/debug/stack_test.go:23 (0x13920)
@ -40,7 +40,7 @@ func TestStack(t *testing.T) {
t.Fatal("too few lines") t.Fatal("too few lines")
} }
check(t, lines[0], "src/pkg/runtime/debug/stack_test.go") check(t, lines[0], "src/pkg/runtime/debug/stack_test.go")
check(t, lines[1], "\t*T.ptrmethod: return Stack()") check(t, lines[1], "\t(*T).ptrmethod: return Stack()")
check(t, lines[2], "src/pkg/runtime/debug/stack_test.go") check(t, lines[2], "src/pkg/runtime/debug/stack_test.go")
check(t, lines[3], "\tT.method: return t.ptrmethod()") check(t, lines[3], "\tT.method: return t.ptrmethod()")
check(t, lines[4], "src/pkg/runtime/debug/stack_test.go") check(t, lines[4], "src/pkg/runtime/debug/stack_test.go")

15
test/fixedbugs/bug350.go Normal file
View File

@ -0,0 +1,15 @@
// errchk $G $D/$F.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 main
type T int
func (T) m() {}
func (T) m() {} // ERROR "T[.]m redeclared"
func (*T) p() {}
func (*T) p() {} // ERROR "[(][*]T[)][.]p redeclared"