Merge pull request #3113 from crazy-max/update-hcl

vendor: update hcl dependencies
This commit is contained in:
Tõnis Tiigi
2025-04-18 15:51:53 -07:00
committed by GitHub
7 changed files with 104 additions and 65 deletions

View File

@ -170,6 +170,9 @@ var ElementFunc = function.New(&function.Spec{
return cty.DynamicPseudoType, errors.New("cannot use element function with an empty list")
}
index = index % len(etys)
if index < 0 {
index += len(etys)
}
return etys[index], nil
default:
return cty.DynamicPseudoType, fmt.Errorf("cannot read elements from %s", listTy.FriendlyName())

View File

@ -26,10 +26,11 @@ var FormatFunc = function.New(&function.Spec{
},
},
VarParam: &function.Parameter{
Name: "args",
Type: cty.DynamicPseudoType,
AllowNull: true,
AllowUnknown: true,
Name: "args",
Type: cty.DynamicPseudoType,
AllowNull: true,
AllowUnknown: true,
AllowDynamicType: true,
},
Type: function.StaticReturnType(cty.String),
RefineResult: refineNonNull,
@ -64,10 +65,11 @@ var FormatListFunc = function.New(&function.Spec{
},
},
VarParam: &function.Parameter{
Name: "args",
Type: cty.DynamicPseudoType,
AllowNull: true,
AllowUnknown: true,
Name: "args",
Type: cty.DynamicPseudoType,
AllowNull: true,
AllowUnknown: true,
AllowDynamicType: true,
},
Type: function.StaticReturnType(cty.List(cty.String)),
RefineResult: refineNonNull,
@ -199,32 +201,32 @@ var FormatListFunc = function.New(&function.Spec{
//
// It supports the following "verbs":
//
// %% Literal percent sign, consuming no value
// %v A default formatting of the value based on type, as described below.
// %#v JSON serialization of the value
// %t Converts to boolean and then produces "true" or "false"
// %b Converts to number, requires integer, produces binary representation
// %d Converts to number, requires integer, produces decimal representation
// %o Converts to number, requires integer, produces octal representation
// %x Converts to number, requires integer, produces hexadecimal representation
// with lowercase letters
// %X Like %x but with uppercase letters
// %e Converts to number, produces scientific notation like -1.234456e+78
// %E Like %e but with an uppercase "E" representing the exponent
// %f Converts to number, produces decimal representation with fractional
// part but no exponent, like 123.456
// %g %e for large exponents or %f otherwise
// %G %E for large exponents or %f otherwise
// %s Converts to string and produces the string's characters
// %q Converts to string and produces JSON-quoted string representation,
// like %v.
// %% Literal percent sign, consuming no value
// %v A default formatting of the value based on type, as described below.
// %#v JSON serialization of the value
// %t Converts to boolean and then produces "true" or "false"
// %b Converts to number, requires integer, produces binary representation
// %d Converts to number, requires integer, produces decimal representation
// %o Converts to number, requires integer, produces octal representation
// %x Converts to number, requires integer, produces hexadecimal representation
// with lowercase letters
// %X Like %x but with uppercase letters
// %e Converts to number, produces scientific notation like -1.234456e+78
// %E Like %e but with an uppercase "E" representing the exponent
// %f Converts to number, produces decimal representation with fractional
// part but no exponent, like 123.456
// %g %e for large exponents or %f otherwise
// %G %E for large exponents or %f otherwise
// %s Converts to string and produces the string's characters
// %q Converts to string and produces JSON-quoted string representation,
// like %v.
//
// The default format selections made by %v are:
//
// string %s
// number %g
// bool %t
// other %#v
// string %s
// number %g
// bool %t
// other %#v
//
// Null values produce the literal keyword "null" for %v and %#v, and produce
// an error otherwise.
@ -236,10 +238,10 @@ var FormatListFunc = function.New(&function.Spec{
// is used. A period with no following number is invalid.
// For examples:
//
// %f default width, default precision
// %9f width 9, default precision
// %.2f default width, precision 2
// %9.2f width 9, precision 2
// %f default width, default precision
// %9f width 9, default precision
// %.2f default width, precision 2
// %9.2f width 9, precision 2
//
// Width and precision are measured in unicode characters (grapheme clusters).
//
@ -256,10 +258,10 @@ var FormatListFunc = function.New(&function.Spec{
// The following additional symbols can be used immediately after the percent
// introducer as flags:
//
// (a space) leave a space where the sign would be if number is positive
// + Include a sign for a number even if it is positive (numeric only)
// - Pad with spaces on the left rather than the right
// 0 Pad with zeros rather than spaces.
// (a space) leave a space where the sign would be if number is positive
// + Include a sign for a number even if it is positive (numeric only)
// - Pad with spaces on the left rather than the right
// 0 Pad with zeros rather than spaces.
//
// Flag characters are ignored for verbs that do not support them.
//

View File

@ -127,6 +127,29 @@ func impliedObjectType(dec *json.Decoder) (cty.Type, error) {
if atys == nil {
atys = make(map[string]cty.Type)
}
if existing, exists := atys[key]; exists {
// We didn't originally have any special treatment for multiple properties
// of the same name, having the type of the last one "win". But that caused
// some confusing error messages when the same input was subsequently used
// with [Unmarshal] using the returned object type, since [Unmarshal] would
// try to fit all of the property values of that name to whatever type
// the last one had, and would likely fail in doing so if the earlier
// properties of the same name had different types.
//
// As a compromise to avoid breaking existing successful use of _consistently-typed_
// redundant properties, we return an error here only if the new type
// differs from the old type. The error message doesn't mention that subtlety
// because the equal type carveout is a compatibility concession rather than
// a feature folks should rely on in new code.
if !existing.Equals(aty) {
// This error message is low-quality because ImpliedType doesn't do
// path tracking while it traverses, unlike Unmarshal. However, this
// is a rare enough case that we don't want to pay the cost of allocating
// another path-tracking buffer that would in most cases be ignored,
// so we just accept a low-context error message. :(
return cty.NilType, fmt.Errorf("duplicate %q property in JSON object", key)
}
}
atys[key] = aty
}

View File

@ -1028,22 +1028,45 @@ func (val Value) HasElement(elem Value) Value {
}
ty := val.Type()
unknownResult := UnknownVal(Bool).RefineNotNull()
if val.IsNull() {
panic("cannot HasElement on null value")
}
if !val.IsKnown() {
return unknownResult
}
if elem.Type() != DynamicPseudoType && val.Type().IsSetType() && val.Type().ElementType() != DynamicPseudoType {
// If we know the type of the given element and the element type of
// the set then they must match for the element to be present, because
// a set can't contain elements of any other type than its element type.
if !elem.Type().Equals(val.ty.ElementType()) {
return False
}
}
if !ty.IsSetType() {
panic("not a set type")
}
if !val.IsKnown() || !elem.IsKnown() {
return UnknownVal(Bool).RefineNotNull()
if !elem.IsKnown() {
return unknownResult
}
if val.IsNull() {
panic("can't call HasElement on a null value")
noMatchResult := False
if !val.IsWhollyKnown() {
// If the set has any unknown elements then a failure to find a
// known-value elem in it means that we don't know whether the
// element is present, rather than that it definitely isn't.
noMatchResult = unknownResult
}
if !ty.ElementType().Equals(elem.Type()) {
// A set can only contain an element of its own element type
return False
}
s := val.v.(set.Set[interface{}])
return BoolVal(s.Has(elem.v))
if !s.Has(elem.v) {
return noMatchResult
}
return True
}
// Length returns the length of the receiver, which must be a collection type