go/types/objectpath: fix tests for pre-go1.11
The behavior of go/types.ObjectString (or perhaps the underlying object) changed at some point. Change-Id: I77f1d13c180e1f78ddc08e80e5d38aa01f425111 Reviewed-on: https://go-review.googlesource.com/138777 Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
parent
b3c0be4c97
commit
792c3e655c
|
@ -11,6 +11,7 @@ import (
|
|||
"go/parser"
|
||||
"go/token"
|
||||
"go/types"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/tools/go/buildutil"
|
||||
|
@ -279,8 +280,8 @@ var Z map[string]struct{ A int }
|
|||
// Check the object strings match.
|
||||
// (We can't check that types are identical because the
|
||||
// objects belong to different type-checker realms.)
|
||||
srcstr := types.ObjectString(srcobj, (*types.Package).Name)
|
||||
binstr := types.ObjectString(binobj, (*types.Package).Name)
|
||||
srcstr := objectString(srcobj)
|
||||
binstr := objectString(binobj)
|
||||
if srcstr != binstr {
|
||||
t.Errorf("ObjectStrings do not match: Object(For(%q)) = %s, want %s",
|
||||
path, srcstr, binstr)
|
||||
|
@ -288,3 +289,13 @@ var Z map[string]struct{ A int }
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func objectString(obj types.Object) string {
|
||||
s := types.ObjectString(obj, (*types.Package).Name)
|
||||
|
||||
// The printing of interface methods changed in go1.11.
|
||||
// This work-around makes the specific test pass with earlier versions.
|
||||
s = strings.Replace(s, "func (interface).Method", "func (p.Foo).Method", -1)
|
||||
|
||||
return s
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue