Extend duplicate check to exported wrappers

Change-Id: I892fca0a374476aa9e65bf26fb03b73d6a0ae75a
Reviewed-on: https://go-review.googlesource.com/1583
Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
Alan Donovan 2014-12-15 16:35:59 -05:00
parent 2ef5a0d23b
commit d569772660
2 changed files with 8 additions and 2 deletions

View File

@ -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?

View File

@ -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