vendor: update github.com/hashicorp/hcl/v2 to v2.19.1

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2023-10-19 14:49:10 +02:00
parent ad674e2666
commit 34b9a629a0
157 changed files with 20123 additions and 5438 deletions

View File

@ -43,14 +43,14 @@ func getConversion(in cty.Type, out cty.Type, unsafe bool) conversion {
out = out.WithoutOptionalAttributesDeep()
if !isKnown {
return cty.UnknownVal(out), nil
return prepareUnknownResult(in.Range(), dynamicReplace(in.Type(), out)), nil
}
if isNull {
// We'll pass through nulls, albeit type converted, and let
// the caller deal with whatever handling they want to do in
// case null values are considered valid in some applications.
return cty.NullVal(out), nil
return cty.NullVal(dynamicReplace(in.Type(), out)), nil
}
}
@ -199,3 +199,64 @@ func retConversion(conv conversion) Conversion {
return conv(in, cty.Path(nil))
}
}
// prepareUnknownResult can apply value refinements to a returned unknown value
// in certain cases where characteristics of the source value or type can
// transfer into range constraints on the result value.
func prepareUnknownResult(sourceRange cty.ValueRange, targetTy cty.Type) cty.Value {
sourceTy := sourceRange.TypeConstraint()
ret := cty.UnknownVal(targetTy)
if sourceRange.DefinitelyNotNull() {
ret = ret.RefineNotNull()
}
switch {
case sourceTy.IsObjectType() && targetTy.IsMapType():
// A map built from an object type always has the same number of
// elements as the source type has attributes.
return ret.Refine().CollectionLength(len(sourceTy.AttributeTypes())).NewValue()
case sourceTy.IsTupleType() && targetTy.IsListType():
// A list built from a typle type always has the same number of
// elements as the source type has elements.
return ret.Refine().CollectionLength(sourceTy.Length()).NewValue()
case sourceTy.IsTupleType() && targetTy.IsSetType():
// When building a set from a tuple type we can't exactly constrain
// the length because some elements might coalesce, but we can
// guarantee an upper limit. We can also guarantee at least one
// element if the tuple isn't empty.
switch l := sourceTy.Length(); l {
case 0, 1:
return ret.Refine().CollectionLength(l).NewValue()
default:
return ret.Refine().
CollectionLengthLowerBound(1).
CollectionLengthUpperBound(sourceTy.Length()).
NewValue()
}
case sourceTy.IsCollectionType() && targetTy.IsCollectionType():
// NOTE: We only reach this function if there is an available
// conversion between the source and target type, so we don't
// need to repeat element type compatibility checks and such here.
//
// If the source value already has a refined length then we'll
// transfer those refinements to the result, because conversion
// does not change length (aside from set element coalescing).
b := ret.Refine()
if targetTy.IsSetType() {
if sourceRange.LengthLowerBound() > 0 {
// If the source has at least one element then the result
// must always have at least one too, because value coalescing
// cannot totally empty the set.
b = b.CollectionLengthLowerBound(1)
}
} else {
b = b.CollectionLengthLowerBound(sourceRange.LengthLowerBound())
}
b = b.CollectionLengthUpperBound(sourceRange.LengthUpperBound())
return b.NewValue()
default:
return ret
}
}