funcs/lang lookup: validate that argument is map or object type

This commit is contained in:
Kristin Laemmert 2018-10-16 12:57:05 -07:00 committed by Martin Atkins
parent c06f24b323
commit 4ec904bca7
1 changed files with 4 additions and 2 deletions

View File

@ -508,9 +508,11 @@ var LookupFunc = function.New(&function.Spec{
// return the default type // return the default type
return args[2].Type(), nil return args[2].Type(), nil
} }
return cty.DynamicPseudoType, nil return cty.DynamicPseudoType, fmt.Errorf("the given object has no attribute %q", key)
default: case ty.IsMapType():
return ty.ElementType(), nil return ty.ElementType(), nil
default:
return cty.NilType, fmt.Errorf("lookup() requires a map as the first argument")
} }
}, },
Impl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) { Impl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) {