]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/gc: do not confuse unexported methods of same name
authorRuss Cox <rsc@golang.org>
Wed, 7 Mar 2012 06:55:17 +0000 (01:55 -0500)
committerRuss Cox <rsc@golang.org>
Wed, 7 Mar 2012 06:55:17 +0000 (01:55 -0500)
Fixes #3146.

R=ken2
CC=golang-dev
https://golang.org/cl/5756074

src/cmd/gc/dcl.c
test/bugs/424.go [deleted file]
test/fixedbugs/bug424.dir/lib.go [moved from test/bugs/424.dir/lib.go with 100% similarity]
test/fixedbugs/bug424.go [moved from test/bugs/424.dir/main.go with 75% similarity]

index 4a0e7430ac614b4cd03d237c2198b21a3c790363..b717625903535818a49523f5d6050bd6910a6fd4 100644 (file)
@@ -1195,10 +1195,17 @@ methodsym(Sym *nsym, Type *t0, int iface)
                if(t0->width < types[tptr]->width)
                        suffix = "·i";
        }
-       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);
+       if(nsym->pkg != s->pkg && !exportname(nsym->name)) {
+               if(t0->sym == S && isptr[t0->etype])
+                       p = smprint("(%-hT).%s.%s%s", t0, nsym->pkg->prefix, nsym->name, suffix);
+               else
+                       p = smprint("%-hT.%s.%s%s", t0, nsym->pkg->prefix, nsym->name, suffix);
+       } else {
+               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);
        free(p);
        return s;
diff --git a/test/bugs/424.go b/test/bugs/424.go
deleted file mode 100644 (file)
index b227760..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-// $G $D/$F.dir/lib.go && $G $D/$F.dir/main.go && $L main.$A && $A.out
-
-// 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.
-
-// Test case for embedded method invocation.
-
-ignored
similarity index 75%
rename from test/bugs/424.dir/main.go
rename to test/fixedbugs/bug424.go
index 64a600b55487d90726b2ffb99d112d8bd84cc750..484febc1d20f7fd78cc4114701c77dd3d84e6e5d 100644 (file)
@@ -1,3 +1,5 @@
+// run
+
 // 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.
@@ -9,7 +11,9 @@
 
 package main
 
-import "./lib"
+import "./bug424.dir"
+import "reflect"
+import "fmt"
 
 type localI interface {
        m() string
@@ -53,9 +57,19 @@ func main() {
                println("BUG: myT2:", i.m(), "called")
        }
 
+       t3 := new(myT3)
+       if t3.m() != "main.localT.m" {
+               println("BUG: t3:", t3.m(), "called")
+       }
+       
        i = new(myT3)
        if i.m() != "main.localT.m" {
+               t := reflect.TypeOf(i)
+               n := t.NumMethod()
+               for j := 0; j < n; j++ {
+                       m := t.Method(j)
+                       fmt.Printf("#%d: %s.%s %s\n", j, m.PkgPath, m.Name, m.Type)
+               }
                println("BUG: myT3:", i.m(), "called")
        }
-
 }