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

View File

@ -508,9 +508,11 @@ var LookupFunc = function.New(&function.Spec{
// return the default type
return args[2].Type(), nil
}
return cty.DynamicPseudoType, nil
default:
return cty.DynamicPseudoType, fmt.Errorf("the given object has no attribute %q", key)
case ty.IsMapType():
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) {