diff --git a/src/go/types/NOTES b/src/go/types/NOTES index 87bbbec6e9..335eb58c5a 100644 --- a/src/go/types/NOTES +++ b/src/go/types/NOTES @@ -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! diff --git a/src/go/types/lookup.go b/src/go/types/lookup.go index e06c0778ef..030541766b 100644 --- a/src/go/types/lookup.go +++ b/src/go/types/lookup.go @@ -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 diff --git a/src/go/types/type.go b/src/go/types/type.go index 2eb8b66bc4..97a6d22189 100644 --- a/src/go/types/type.go +++ b/src/go/types/type.go @@ -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) }