mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-10 05:27:07 +08:00
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:
81
vendor/github.com/zclconf/go-cty/cty/convert/conversion_collection.go
generated
vendored
81
vendor/github.com/zclconf/go-cty/cty/convert/conversion_collection.go
generated
vendored
@ -39,6 +39,11 @@ func conversionCollectionToList(ety cty.Type, conv conversion) conversion {
|
||||
return cty.NilVal, err
|
||||
}
|
||||
}
|
||||
|
||||
if val.IsNull() {
|
||||
val = cty.NullVal(val.Type().WithoutOptionalAttributesDeep())
|
||||
}
|
||||
|
||||
elems = append(elems, val)
|
||||
|
||||
i++
|
||||
@ -50,7 +55,7 @@ func conversionCollectionToList(ety cty.Type, conv conversion) conversion {
|
||||
if ety == cty.DynamicPseudoType {
|
||||
return cty.ListValEmpty(val.Type().ElementType()), nil
|
||||
}
|
||||
return cty.ListValEmpty(ety), nil
|
||||
return cty.ListValEmpty(ety.WithoutOptionalAttributesDeep()), nil
|
||||
}
|
||||
|
||||
if !cty.CanListVal(elems) {
|
||||
@ -88,6 +93,11 @@ func conversionCollectionToSet(ety cty.Type, conv conversion) conversion {
|
||||
return cty.NilVal, err
|
||||
}
|
||||
}
|
||||
|
||||
if val.IsNull() {
|
||||
val = cty.NullVal(val.Type().WithoutOptionalAttributesDeep())
|
||||
}
|
||||
|
||||
elems = append(elems, val)
|
||||
|
||||
i++
|
||||
@ -99,7 +109,7 @@ func conversionCollectionToSet(ety cty.Type, conv conversion) conversion {
|
||||
if ety == cty.DynamicPseudoType {
|
||||
return cty.SetValEmpty(val.Type().ElementType()), nil
|
||||
}
|
||||
return cty.SetValEmpty(ety), nil
|
||||
return cty.SetValEmpty(ety.WithoutOptionalAttributesDeep()), nil
|
||||
}
|
||||
|
||||
if !cty.CanSetVal(elems) {
|
||||
@ -180,7 +190,7 @@ func conversionTupleToSet(tupleType cty.Type, setEty cty.Type, unsafe bool) conv
|
||||
if len(tupleEtys) == 0 {
|
||||
// Empty tuple short-circuit
|
||||
return func(val cty.Value, path cty.Path) (cty.Value, error) {
|
||||
return cty.SetValEmpty(setEty), nil
|
||||
return cty.SetValEmpty(setEty.WithoutOptionalAttributesDeep()), nil
|
||||
}
|
||||
}
|
||||
|
||||
@ -242,6 +252,11 @@ func conversionTupleToSet(tupleType cty.Type, setEty cty.Type, unsafe bool) conv
|
||||
return cty.NilVal, err
|
||||
}
|
||||
}
|
||||
|
||||
if val.IsNull() {
|
||||
val = cty.NullVal(val.Type().WithoutOptionalAttributesDeep())
|
||||
}
|
||||
|
||||
elems = append(elems, val)
|
||||
|
||||
i++
|
||||
@ -265,7 +280,7 @@ func conversionTupleToList(tupleType cty.Type, listEty cty.Type, unsafe bool) co
|
||||
if len(tupleEtys) == 0 {
|
||||
// Empty tuple short-circuit
|
||||
return func(val cty.Value, path cty.Path) (cty.Value, error) {
|
||||
return cty.ListValEmpty(listEty), nil
|
||||
return cty.ListValEmpty(listEty.WithoutOptionalAttributesDeep()), nil
|
||||
}
|
||||
}
|
||||
|
||||
@ -357,7 +372,7 @@ func conversionObjectToMap(objectType cty.Type, mapEty cty.Type, unsafe bool) co
|
||||
if len(objectAtys) == 0 {
|
||||
// Empty object short-circuit
|
||||
return func(val cty.Value, path cty.Path) (cty.Value, error) {
|
||||
return cty.MapValEmpty(mapEty), nil
|
||||
return cty.MapValEmpty(mapEty.WithoutOptionalAttributesDeep()), nil
|
||||
}
|
||||
}
|
||||
|
||||
@ -448,13 +463,28 @@ func conversionMapToObject(mapType cty.Type, objType cty.Type, unsafe bool) conv
|
||||
|
||||
elemConvs[name] = getConversion(mapEty, objectAty, unsafe)
|
||||
if elemConvs[name] == nil {
|
||||
// If any of our element conversions are impossible, then the our
|
||||
// whole conversion is impossible.
|
||||
// This means that this conversion is impossible. Typically, we
|
||||
// would give up at this point and declare the whole conversion
|
||||
// impossible. But, if this attribute is optional then maybe we will
|
||||
// be able to do this conversion anyway provided the actual concrete
|
||||
// map doesn't have this value set.
|
||||
//
|
||||
// We only do this in "unsafe" mode, because we cannot guarantee
|
||||
// that the returned conversion will actually succeed once applied.
|
||||
if objType.AttributeOptional(name) && unsafe {
|
||||
// This attribute is optional, so let's leave this conversion in
|
||||
// as a nil, and we can error later if we actually have to
|
||||
// convert this.
|
||||
continue
|
||||
}
|
||||
|
||||
// Otherwise, give up. This conversion is impossible as we have a
|
||||
// required attribute that doesn't match the map's inner type.
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// If we fall out here then a conversion is possible, using the
|
||||
// If we fall out here then a conversion may be possible, using the
|
||||
// element conversions in elemConvs
|
||||
return func(val cty.Value, path cty.Path) (cty.Value, error) {
|
||||
elems := make(map[string]cty.Value, len(elemConvs))
|
||||
@ -474,12 +504,43 @@ func conversionMapToObject(mapType cty.Type, objType cty.Type, unsafe bool) conv
|
||||
Key: name,
|
||||
}
|
||||
|
||||
conv := elemConvs[name.AsString()]
|
||||
if conv != nil {
|
||||
// There are 3 cases here:
|
||||
// 1. This attribute is not in elemConvs
|
||||
// 2. This attribute is in elemConvs and is not nil
|
||||
// 3. This attribute is in elemConvs and is nil.
|
||||
|
||||
// In case 1, we do not enter any of the branches below. This case
|
||||
// means the attribute type is the same between the map and the
|
||||
// object, and we don't need to do any conversion.
|
||||
|
||||
if conv, ok := elemConvs[name.AsString()]; conv != nil {
|
||||
// This is case 2. The attribute type is different between the
|
||||
// map and the object, and we know how to convert between them.
|
||||
// So, we reset val to be the converted value and carry on.
|
||||
val, err = conv(val, elemPath)
|
||||
if err != nil {
|
||||
return cty.NilVal, err
|
||||
}
|
||||
} else if ok {
|
||||
// This is case 3 and it is an error. The attribute types are
|
||||
// different between the map and the object, but we cannot
|
||||
// convert between them.
|
||||
//
|
||||
// Now typically, this would be picked earlier on when we were
|
||||
// building elemConvs. However, in the case of optional
|
||||
// attributes there was a chance we could still convert the
|
||||
// overall object even if this particular attribute was not
|
||||
// convertable. This is because it could have not been set in
|
||||
// the map, and we could skip over it here and set a null value.
|
||||
//
|
||||
// Since we reached this branch, we know that map did actually
|
||||
// contain a non-convertable optional attribute. This means we
|
||||
// error.
|
||||
return cty.NilVal, path.NewErrorf("map element type is incompatible with attribute %q: %s", name.AsString(), MismatchMessage(val.Type(), objType.AttributeType(name.AsString())))
|
||||
}
|
||||
|
||||
if val.IsNull() {
|
||||
val = cty.NullVal(val.Type().WithoutOptionalAttributesDeep())
|
||||
}
|
||||
|
||||
elems[name.AsString()] = val
|
||||
|
Reference in New Issue
Block a user