go/types: a type parameter acts like a named type; fix predicate and test

Change-Id: Ibe9f074d516200b9b12c26a270e62defc024eeac
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/769347
Reviewed-by: Robert Griesemer <gri@google.com>
This commit is contained in:
Robert Griesemer 2020-06-11 23:11:18 -07:00
parent bc77b007e5
commit bbdb05760f
2 changed files with 5 additions and 5 deletions

View File

@ -15,7 +15,7 @@ import (
// isNamed may be called with types that are not fully set up.
func isNamed(typ Type) bool {
switch typ.(type) {
case *Basic, *Named, *instance:
case *Basic, *Named, *TypeParam, *instance:
return true
}
return false

View File

@ -181,13 +181,13 @@ func at(type T interface{ type []E }, E interface{})(x T, i int) E {
}
// A generic type inside a function acts like a named type. Its underlying
// type is defined by the type list in the tybe bound, if any.
// type is itself, its "operational type" is defined by the type list in
// the tybe bound, if any.
func _(type T interface{type int})(x T) {
type myint int
var _ int = x
var _ int = int(x)
var _ T = 42
var _ T = int(42)
var _ T = myint(42)
var _ T = T(myint(42))
}
// Indexing a generic type with an array type bound checks length.