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:
parent
2ef5a0d23b
commit
d569772660
|
@ -464,7 +464,10 @@ func (f *Function) emit(instr Instruction) Value {
|
||||||
// (i.e. from == f.Pkg.Object), they are rendered without the package path.
|
// (i.e. from == f.Pkg.Object), they are rendered without the package path.
|
||||||
// For example: "IsNaN", "(*Buffer).Bytes", etc.
|
// 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 {
|
func (f *Function) RelString(from *types.Package) string {
|
||||||
// Anonymous?
|
// Anonymous?
|
||||||
|
|
|
@ -10,6 +10,7 @@ package ssa_test
|
||||||
// Run with "go test -cpu=8 to" set GOMAXPROCS.
|
// Run with "go test -cpu=8 to" set GOMAXPROCS.
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"go/ast"
|
||||||
"go/build"
|
"go/build"
|
||||||
"go/token"
|
"go/token"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
@ -82,9 +83,11 @@ func TestStdlib(t *testing.T) {
|
||||||
allFuncs := ssautil.AllFunctions(prog)
|
allFuncs := ssautil.AllFunctions(prog)
|
||||||
|
|
||||||
// Check that all non-synthetic functions have distinct names.
|
// 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)
|
byName := make(map[string]*ssa.Function)
|
||||||
for fn := range allFuncs {
|
for fn := range allFuncs {
|
||||||
if fn.Synthetic == "" {
|
if fn.Synthetic == "" || ast.IsExported(fn.Name()) {
|
||||||
str := fn.String()
|
str := fn.String()
|
||||||
prev := byName[str]
|
prev := byName[str]
|
||||||
byName[str] = fn
|
byName[str] = fn
|
||||||
|
|
Loading…
Reference in New Issue