From d56977266019f070ce097c082a929f54de17e473 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Mon, 15 Dec 2014 16:35:59 -0500 Subject: [PATCH] Extend duplicate check to exported wrappers Change-Id: I892fca0a374476aa9e65bf26fb03b73d6a0ae75a Reviewed-on: https://go-review.googlesource.com/1583 Reviewed-by: Robert Griesemer --- go/ssa/func.go | 5 ++++- go/ssa/stdlib_test.go | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/go/ssa/func.go b/go/ssa/func.go index 621ec1d0..fec527b5 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 4935db00..5e12aeb5 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