[dev.typeparams] go/types: make Interface.obj a *TypeName

This is a straightforward port of CL 332011 to go/types.

Change-Id: I682791886c8496c52094f3688e36934afbd7a241
Reviewed-on: https://go-review.googlesource.com/c/go/+/335035
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
Rob Findley 2021-07-16 10:33:59 -04:00 committed by Robert Findley
parent 0f4198b5e2
commit de209e693a
3 changed files with 5 additions and 6 deletions

View file

@ -482,11 +482,10 @@ func (check *Checker) selector(x *operand, e *ast.SelectorExpr) {
var why string
if tpar := asTypeParam(x.typ); tpar != nil {
// Type parameter bounds don't specify fields, so don't mention "field".
switch obj := tpar.Bound().obj.(type) {
case nil:
if tname := tpar.Bound().obj; tname != nil {
why = check.sprintf("interface %s has no method %s", tname.name, sel)
} else {
why = check.sprintf("type bound for %s has no method %s", x.typ, sel)
case *TypeName:
why = check.sprintf("interface %s has no method %s", obj.name, sel)
}
} else {
why = check.sprintf("type %s has no field or method %s", x.typ, sel)

View file

@ -27,7 +27,7 @@ func TestSizeof(t *testing.T) {
{Tuple{}, 12, 24},
{Signature{}, 44, 88},
{Union{}, 24, 48},
{Interface{}, 44, 88},
{Interface{}, 40, 80},
{Map{}, 16, 32},
{Chan{}, 12, 24},
{Named{}, 84, 160},

View file

@ -258,7 +258,7 @@ func (s *Signature) Variadic() bool { return s.variadic }
// An Interface represents an interface type.
type Interface struct {
obj Object // type name object defining this interface; or nil (for better error messages)
obj *TypeName // type name object defining this interface; or nil (for better error messages)
methods []*Func // ordered list of explicitly declared methods
embeddeds []Type // ordered list of explicitly embedded elements
embedPos *[]token.Pos // positions of embedded elements; or nil (for error messages) - use pointer to save space