aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Donovan <adonovan@google.com>2014-12-15 16:35:59 -0500
committerAlan Donovan <adonovan@google.com>2015-01-23 18:36:53 +0000
commitd56977266019f070ce097c082a929f54de17e473 (patch)
treed723b51828f1e4641a291eafde533ff0a223f6a4
parent2ef5a0d23bc4e07573bb094b97e96c9cd9844fca (diff)
downloadtools-d56977266019f070ce097c082a929f54de17e473.tar.gz
Extend duplicate check to exported wrappers
Change-Id: I892fca0a374476aa9e65bf26fb03b73d6a0ae75a Reviewed-on: https://go-review.googlesource.com/1583 Reviewed-by: Robert Griesemer <gri@golang.org>
-rw-r--r--go/ssa/func.go5
-rw-r--r--go/ssa/stdlib_test.go5
2 files changed, 8 insertions, 2 deletions
diff --git a/go/ssa/func.go b/go/ssa/func.go
index 621ec1d..fec527b 100644
--- a/go/ssa/func.go
+++ b/go/ssa/func.go
@@ -464,7 +464,10 @@ func (f *Function) emit(instr Instruction) Value {
// (i.e. from == f.Pkg.Object), they are rendered without the package path.
// For example: "IsNaN", "(*Buffer).Bytes", etc.
//
-// Invariant: all non-synthetic functions have distinct package-qualified names.
+// All non-synthetic functions have distinct package-qualified names.
+// (But two methods may have the same name "(T).f" if one is a synthetic
+// wrapper promoting a non-exported method "f" from another package; in
+// that case, the strings are equal but the identifiers "f" are distinct.)
//
func (f *Function) RelString(from *types.Package) string {
// Anonymous?
diff --git a/go/ssa/stdlib_test.go b/go/ssa/stdlib_test.go
index 4935db0..5e12aeb 100644
--- a/go/ssa/stdlib_test.go
+++ b/go/ssa/stdlib_test.go
@@ -10,6 +10,7 @@ package ssa_test
// Run with "go test -cpu=8 to" set GOMAXPROCS.
import (
+ "go/ast"
"go/build"
"go/token"
"runtime"
@@ -82,9 +83,11 @@ func TestStdlib(t *testing.T) {
allFuncs := ssautil.AllFunctions(prog)
// Check that all non-synthetic functions have distinct names.
+ // Synthetic wrappers for exported methods should be distinct too,
+ // except for unexported ones (explained at (*Function).RelString).
byName := make(map[string]*ssa.Function)
for fn := range allFuncs {
- if fn.Synthetic == "" {
+ if fn.Synthetic == "" || ast.IsExported(fn.Name()) {
str := fn.String()
prev := byName[str]
byName[str] = fn