Make IsResource tolerant of types.Named types

This commit is contained in:
joeduffy 2017-04-27 11:52:59 -07:00
parent 70f6d88a5b
commit dd032e0784
2 changed files with 6 additions and 1 deletions

View file

@ -400,7 +400,7 @@ func (g *RPCGenerator) GenTypeName(t types.Type) string {
case *types.Named:
obj := u.Obj()
// For resource types, simply emit an ID, since that is what will have been serialized.
if isres, _ := IsResource(obj, u.Underlying()); isres {
if isres, _ := IsResource(obj, u); isres {
return "resource.ID"
}

View file

@ -27,6 +27,11 @@ var (
// IsResource checks whether a type is a special IDL resource. If yes, it returns true for the first boolean, and the
// second boolean indicates whether the resource is named or not.
func IsResource(obj *types.TypeName, t types.Type) (bool, bool) {
// If a named type, fetch the underlying.
if n, is := t.(*types.Named); is {
t = n.Underlying()
}
// If this is a resource type itself, then we're done.
if isres, isname := isResourceObj(obj); isres {
return isres, isname