Properly fetch pointer elements
This commit is contained in:
parent
42ce8744ce
commit
f5c6af505a
2 changed files with 13 additions and 5 deletions
|
@ -336,7 +336,12 @@ func (chk *Checker) CheckIDLType(t types.Type, opts PropertyOptions) error {
|
|||
case *types.Pointer:
|
||||
// A pointer is OK so long as the field is either optional or a resource type.
|
||||
if !opts.Optional {
|
||||
if isres, _ := IsResource(nil, ft.Elem()); !isres {
|
||||
elem := ft.Elem()
|
||||
isres := false
|
||||
if named, isnamed := elem.(*types.Named); isnamed {
|
||||
isres, _ = IsResource(named.Obj(), named)
|
||||
}
|
||||
if !isres {
|
||||
return errors.New("bad pointer; must be optional or a resource type")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"reflect"
|
||||
|
||||
"github.com/pulumi/coconut/pkg/resource/idl"
|
||||
"github.com/pulumi/coconut/pkg/util/contract"
|
||||
)
|
||||
|
||||
func IsPrimitive(t types.Type) bool {
|
||||
|
@ -27,16 +28,18 @@ 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()
|
||||
}
|
||||
contract.Assert(obj != nil)
|
||||
|
||||
// If this is a resource type itself, then we're done.
|
||||
if isres, isname := isResourceObj(obj); isres {
|
||||
return isres, isname
|
||||
}
|
||||
|
||||
// If a named type, fetch the underlying.
|
||||
if n, is := t.(*types.Named); is {
|
||||
t = n.Underlying()
|
||||
}
|
||||
|
||||
if s, is := t.(*types.Struct); is {
|
||||
// Otherwise, it's a resource if it has an embedded resource field.
|
||||
for i := 0; i < s.NumFields(); i++ {
|
||||
|
|
Loading…
Reference in a new issue