Skip to content

Commit

Permalink
Extend duplicate check to exported wrappers
Browse files Browse the repository at this point in the history
Change-Id: I892fca0a374476aa9e65bf26fb03b73d6a0ae75a
Reviewed-on: https://go-review.googlesource.com/1583
Reviewed-by: Robert Griesemer <[email protected]>
  • Loading branch information
adonovan committed Jan 23, 2015
1 parent 2ef5a0d commit d569772
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion go/ssa/func.go
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
5 changes: 4 additions & 1 deletion go/ssa/stdlib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package ssa_test
// Run with "go test -cpu=8 to" set GOMAXPROCS.

import (
"go/ast"
"go/build"
"go/token"
"runtime"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d569772

Please sign in to comment.