go/types: provide accessor to type arguments for instantiated types

Plus a couple of minor unrelated comment updates.

Change-Id: I38554c9ae9143172ea65da6c270fba10772c194b
This commit is contained in:
Robert Griesemer 2020-03-03 09:29:29 -08:00
parent 74ba054b38
commit 1211c65e41
3 changed files with 9 additions and 3 deletions

View File

@ -4,7 +4,6 @@ so we have a better track record. I only switched to this file in Nov 2019, henc
----------------------------------------------------------------------------------------------------
TODO
- type assertions on/against parameterized types
- use Underlying() to return a type parameter's bound? investigate!
- debug (and error msg) printing of generic instantiated types needs some work
- improve error messages!

View File

@ -390,8 +390,8 @@ func (check *Checker) missingMethod(V Type, T *Interface, static bool) (method,
// method required by V and whether it is missing or just has the wrong type.
// The receiver may be nil if assertableTo is invoked through an exported API call
// (such as AssertableTo), i.e., when all methods have been type-checked.
// If strict (or the global constant forceStrict) is set, assertions are strict;
// i.e., assertions that are guaranteed to fail are not permitted.
// If strict (or the global constant forceStrict) is set, assertions that
// are known to fail are not permitted.
func (check *Checker) assertableTo(V *Interface, T Type, strict bool) (method, wrongType *Func) {
// no static check is required if T is an interface
// spec: "If T is an interface type, x.(T) asserts that the

View File

@ -512,9 +512,16 @@ func NewNamed(obj *TypeName, underlying Type, methods []*Func) *Named {
// Obj returns the type name for the named type t.
func (t *Named) Obj() *TypeName { return t.obj }
// TODO(gri) Come up with a better representation and API to distinguish
// between parameterized instantiated and non-instantiated types.
// TParams returns the type parameters of the named type t, or nil.
// The result is non-nil for an (originally) parameterized type even if it is instantiated.
func (t *Named) TParams() []*TypeName { return t.tparams }
// TArgs returns the type arguments after instantiation of the named type t, or nil if not instantiated.
func (t *Named) TArgs() []Type { return t.targs }
// NumMethods returns the number of explicit methods whose receiver is named type t.
func (t *Named) NumMethods() int { return len(t.methods) }