vendor: github.com/zclconf/go-cty v1.16.0

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2025-01-13 18:00:34 +01:00
parent 26026810fe
commit 66ecb53fa7
8 changed files with 38 additions and 28 deletions

View File

@ -171,12 +171,16 @@ func getConversionKnown(in cty.Type, out cty.Type, unsafe bool) conversion {
}
if out.IsCapsuleType() {
if fn := out.CapsuleOps().ConversionTo; fn != nil {
return conversionToCapsule(in, out, fn)
if conv := conversionToCapsule(in, out, fn); conv != nil {
return conv
}
}
}
if in.IsCapsuleType() {
if fn := in.CapsuleOps().ConversionFrom; fn != nil {
return conversionFromCapsule(in, out, fn)
if conv := conversionFromCapsule(in, out, fn); conv != nil {
return conv
}
}
}
// No conversion operation is available, then.

View File

@ -162,7 +162,7 @@ func conversionCollectionToMap(ety cty.Type, conv conversion) conversion {
if ety == cty.DynamicPseudoType {
return cty.MapValEmpty(val.Type().ElementType()), nil
}
return cty.MapValEmpty(ety), nil
return cty.MapValEmpty(ety.WithoutOptionalAttributesDeep()), nil
}
if ety.IsCollectionType() || ety.IsObjectType() {

View File

@ -251,15 +251,25 @@ func (f Function) Call(args []cty.Value) (val cty.Value, err error) {
if err != nil {
return cty.NilVal, err
}
var resultMarks []cty.ValueMarks
// If we are returning an unknown early due to some unknown in the
// arguments, we first need to complete the iteration over all the args
// to ensure we collect as many marks as possible for resultMarks.
returnUnknown := false
if dynTypeArgs {
// returnTypeForValues sets this if any argument was inexactly typed
// and the corresponding parameter did not indicate it could deal with
// that. In that case we also avoid calling the implementation function
// because it will also typically not be ready to deal with that case.
return cty.UnknownVal(expectedType), nil
returnUnknown = true
}
if refineResult := f.spec.RefineResult; refineResult != nil {
// If returnUnknown is set already, it means we don't have a refinement
// because of dynTypeArgs, but we may still need to collect marks from the
// rest of the arguments.
if refineResult := f.spec.RefineResult; refineResult != nil && !returnUnknown {
// If this function has a refinement callback then we'll refine
// our result value in the same way regardless of how we return.
// It's the function author's responsibility to ensure that the
@ -280,15 +290,10 @@ func (f Function) Call(args []cty.Value) (val cty.Value, err error) {
// values and marked values.
posArgs := args[:len(f.spec.Params)]
varArgs := args[len(f.spec.Params):]
var resultMarks []cty.ValueMarks
for i, spec := range f.spec.Params {
val := posArgs[i]
if !val.IsKnown() && !spec.AllowUnknown {
return cty.UnknownVal(expectedType), nil
}
if !spec.AllowMarked {
unwrappedVal, marks := val.UnmarkDeep()
if len(marks) > 0 {
@ -305,14 +310,15 @@ func (f Function) Call(args []cty.Value) (val cty.Value, err error) {
args = newArgs
}
}
if !val.IsKnown() && !spec.AllowUnknown {
returnUnknown = true
}
}
if f.spec.VarParam != nil {
spec := f.spec.VarParam
for i, val := range varArgs {
if !val.IsKnown() && !spec.AllowUnknown {
return cty.UnknownVal(expectedType), nil
}
if !spec.AllowMarked {
unwrappedVal, marks := val.UnmarkDeep()
if len(marks) > 0 {
@ -323,9 +329,16 @@ func (f Function) Call(args []cty.Value) (val cty.Value, err error) {
args = newArgs
}
}
if !val.IsKnown() && !spec.AllowUnknown {
returnUnknown = true
}
}
}
if returnUnknown {
return cty.UnknownVal(expectedType).WithMarks(resultMarks...), nil
}
var retVal cty.Value
{
// Intercept any panics from the function and return them as normal errors,

View File

@ -147,12 +147,6 @@ var ElementFunc = function.New(&function.Spec{
},
Type: func(args []cty.Value) (cty.Type, error) {
list := args[0]
index := args[1]
if index.IsKnown() {
if index.LessThan(cty.NumberIntVal(0)).True() {
return cty.DynamicPseudoType, fmt.Errorf("cannot use element function with a negative index")
}
}
listTy := list.Type()
switch {
@ -189,10 +183,6 @@ var ElementFunc = function.New(&function.Spec{
return cty.DynamicVal, fmt.Errorf("invalid index: %s", err)
}
if args[1].LessThan(cty.NumberIntVal(0)).True() {
return cty.DynamicVal, fmt.Errorf("cannot use element function with a negative index")
}
input, marks := args[0].Unmark()
if !input.IsKnown() {
return cty.UnknownVal(retType), nil
@ -203,6 +193,9 @@ var ElementFunc = function.New(&function.Spec{
return cty.DynamicVal, errors.New("cannot use element function with an empty list")
}
index = index % l
if index < 0 {
index += l
}
// We did all the necessary type checks in the type function above,
// so this is guaranteed not to fail.

View File

@ -213,7 +213,7 @@ func transform(path Path, val Value, t Transformer) (Value, error) {
atys := ty.AttributeTypes()
newAVs := make(map[string]Value)
for name := range atys {
av := val.GetAttr(name)
av := rawVal.GetAttr(name)
path := append(path, GetAttrStep{
Name: name,
})