bump github.com/zclconf/go-cty from 1.7.1 to 1.10.0

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2022-01-13 14:32:10 +01:00
parent 785c861233
commit b67bdedb23
30 changed files with 13397 additions and 193 deletions

View File

@ -11,8 +11,9 @@ import (
var ConcatFunc = function.New(&function.Spec{
Params: []function.Parameter{},
VarParam: &function.Parameter{
Name: "seqs",
Type: cty.DynamicPseudoType,
Name: "seqs",
Type: cty.DynamicPseudoType,
AllowMarked: true,
},
Type: func(args []cty.Value) (ret cty.Type, err error) {
if len(args) == 0 {
@ -42,6 +43,10 @@ var ConcatFunc = function.New(&function.Spec{
etys := make([]cty.Type, 0, len(args))
for i, val := range args {
// Discard marks for nested values, as we only need to handle types
// and lengths.
val, _ := val.UnmarkDeep()
ety := val.Type()
switch {
case ety.IsTupleType():
@ -75,6 +80,7 @@ var ConcatFunc = function.New(&function.Spec{
// given values will be lists and that they will either be of
// retType or of something we can convert to retType.
vals := make([]cty.Value, 0, len(args))
var markses []cty.ValueMarks // remember any marked lists we find
for i, list := range args {
list, err = convert.Convert(list, retType)
if err != nil {
@ -83,6 +89,11 @@ var ConcatFunc = function.New(&function.Spec{
return cty.NilVal, function.NewArgError(i, err)
}
list, listMarks := list.Unmark()
if len(listMarks) > 0 {
markses = append(markses, listMarks)
}
it := list.ElementIterator()
for it.Next() {
_, v := it.Element()
@ -90,10 +101,10 @@ var ConcatFunc = function.New(&function.Spec{
}
}
if len(vals) == 0 {
return cty.ListValEmpty(retType.ElementType()), nil
return cty.ListValEmpty(retType.ElementType()).WithMarks(markses...), nil
}
return cty.ListVal(vals), nil
return cty.ListVal(vals).WithMarks(markses...), nil
case retType.IsTupleType():
// If retType is a tuple type then we could have a mixture of
// lists and tuples but we know they all have known values
@ -101,8 +112,14 @@ var ConcatFunc = function.New(&function.Spec{
// concatenating them all together will produce a tuple of
// retType because of the work we did in the Type function above.
vals := make([]cty.Value, 0, len(args))
var markses []cty.ValueMarks // remember any marked seqs we find
for _, seq := range args {
seq, seqMarks := seq.Unmark()
if len(seqMarks) > 0 {
markses = append(markses, seqMarks)
}
// Both lists and tuples support ElementIterator, so this is easy.
it := seq.ElementIterator()
for it.Next() {
@ -111,7 +128,7 @@ var ConcatFunc = function.New(&function.Spec{
}
}
return cty.TupleVal(vals), nil
return cty.TupleVal(vals).WithMarks(markses...), nil
default:
// should never happen if Type is working correctly above
panic("unsupported return type")