vendor: update github.com/zclconf/go-cty to v1.14.1

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2023-10-19 14:52:01 +02:00
parent 457dc402d3
commit beca8b6adf
20 changed files with 96 additions and 12771 deletions

View File

@ -4,7 +4,7 @@ import (
"fmt"
"unicode/utf8"
"github.com/apparentlymart/go-textseg/v13/textseg"
"github.com/apparentlymart/go-textseg/v15/textseg"
"golang.org/x/text/unicode/norm"
)
@ -26,10 +26,6 @@ import (
// application can guarantee that the remainder of the string will not begin
// with combining marks then it is safe to instead just normalize the prefix
// string with [Normalize].
//
// Note that this function only takes into account normalization boundaries
// and does _not_ take into account grapheme cluster boundaries as defined
// by Unicode Standard Annex #29.
func SafeKnownPrefix(prefix string) string {
prefix = Normalize(prefix)

View File

@ -122,20 +122,13 @@ func (f Function) ReturnType(argTypes []cty.Type) (cty.Type, error) {
return f.ReturnTypeForValues(vals)
}
// ReturnTypeForValues is similar to ReturnType but can be used if the caller
// already knows the values of some or all of the arguments, in which case
// the function may be able to determine a more definite result if its
// return type depends on the argument *values*.
//
// For any arguments whose values are not known, pass an Unknown value of
// the appropriate type.
func (f Function) ReturnTypeForValues(args []cty.Value) (ty cty.Type, err error) {
func (f Function) returnTypeForValues(args []cty.Value) (ty cty.Type, dynTypedArgs bool, err error) {
var posArgs []cty.Value
var varArgs []cty.Value
if f.spec.VarParam == nil {
if len(args) != len(f.spec.Params) {
return cty.Type{}, fmt.Errorf(
return cty.Type{}, false, fmt.Errorf(
"wrong number of arguments (%d required; %d given)",
len(f.spec.Params), len(args),
)
@ -145,7 +138,7 @@ func (f Function) ReturnTypeForValues(args []cty.Value) (ty cty.Type, err error)
varArgs = nil
} else {
if len(args) < len(f.spec.Params) {
return cty.Type{}, fmt.Errorf(
return cty.Type{}, false, fmt.Errorf(
"wrong number of arguments (at least %d required; %d given)",
len(f.spec.Params), len(args),
)
@ -174,7 +167,7 @@ func (f Function) ReturnTypeForValues(args []cty.Value) (ty cty.Type, err error)
}
if val.IsNull() && !spec.AllowNull {
return cty.Type{}, NewArgErrorf(i, "argument must not be null")
return cty.Type{}, false, NewArgErrorf(i, "argument must not be null")
}
// AllowUnknown is ignored for type-checking, since we expect to be
@ -184,13 +177,13 @@ func (f Function) ReturnTypeForValues(args []cty.Value) (ty cty.Type, err error)
if val.Type() == cty.DynamicPseudoType {
if !spec.AllowDynamicType {
return cty.DynamicPseudoType, nil
return cty.DynamicPseudoType, true, nil
}
} else if errs := val.Type().TestConformance(spec.Type); errs != nil {
// For now we'll just return the first error in the set, since
// we don't have a good way to return the whole list here.
// Would be good to do something better at some point...
return cty.Type{}, NewArgError(i, errs[0])
return cty.Type{}, false, NewArgError(i, errs[0])
}
}
@ -209,18 +202,18 @@ func (f Function) ReturnTypeForValues(args []cty.Value) (ty cty.Type, err error)
}
if val.IsNull() && !spec.AllowNull {
return cty.Type{}, NewArgErrorf(realI, "argument must not be null")
return cty.Type{}, false, NewArgErrorf(realI, "argument must not be null")
}
if val.Type() == cty.DynamicPseudoType {
if !spec.AllowDynamicType {
return cty.DynamicPseudoType, nil
return cty.DynamicPseudoType, true, nil
}
} else if errs := val.Type().TestConformance(spec.Type); errs != nil {
// For now we'll just return the first error in the set, since
// we don't have a good way to return the whole list here.
// Would be good to do something better at some point...
return cty.Type{}, NewArgError(i, errs[0])
return cty.Type{}, false, NewArgError(i, errs[0])
}
}
}
@ -234,17 +227,37 @@ func (f Function) ReturnTypeForValues(args []cty.Value) (ty cty.Type, err error)
}
}()
return f.spec.Type(args)
ty, err = f.spec.Type(args)
return ty, false, err
}
// ReturnTypeForValues is similar to ReturnType but can be used if the caller
// already knows the values of some or all of the arguments, in which case
// the function may be able to determine a more definite result if its
// return type depends on the argument *values*.
//
// For any arguments whose values are not known, pass an Unknown value of
// the appropriate type.
func (f Function) ReturnTypeForValues(args []cty.Value) (ty cty.Type, err error) {
ty, _, err = f.returnTypeForValues(args)
return ty, err
}
// Call actually calls the function with the given arguments, which must
// conform to the function's parameter specification or an error will be
// returned.
func (f Function) Call(args []cty.Value) (val cty.Value, err error) {
expectedType, err := f.ReturnTypeForValues(args)
expectedType, dynTypeArgs, err := f.returnTypeForValues(args)
if err != nil {
return cty.NilVal, err
}
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
}
if refineResult := f.spec.RefineResult; refineResult != nil {
// If this function has a refinement callback then we'll refine

View File

@ -6,7 +6,7 @@ import (
"math/big"
"strings"
"github.com/apparentlymart/go-textseg/v13/textseg"
"github.com/apparentlymart/go-textseg/v15/textseg"
"github.com/zclconf/go-cty/cty"
"github.com/zclconf/go-cty/cty/convert"

View File

@ -6,7 +6,7 @@ import (
"sort"
"strings"
"github.com/apparentlymart/go-textseg/v13/textseg"
"github.com/apparentlymart/go-textseg/v15/textseg"
"github.com/zclconf/go-cty/cty"
"github.com/zclconf/go-cty/cty/function"

View File

@ -225,7 +225,9 @@ func (s IndexStep) Apply(val Value) (Value, error) {
return NilVal, errors.New("key value not number or string")
}
has := val.HasIndex(s.Key)
// This value needs to be stripped of marks to check True(), but Index will
// apply the correct marks for the result.
has, _ := val.HasIndex(s.Key).Unmark()
if !has.IsKnown() {
return UnknownVal(val.Type().ElementType()), nil
}

View File

@ -44,7 +44,17 @@ func (v Value) Refine() *RefinementBuilder {
var wip unknownValRefinement
switch {
case ty == DynamicPseudoType && !v.IsKnown():
panic("cannot refine an unknown value of an unknown type")
// This case specifically matches DynamicVal, which is constrained
// by backward compatibility to be a singleton and so we cannot allow
// any refinements to it.
// To preserve the typical assumption that DynamicVal is a safe
// placeholder to use when no value is known at all, we silently
// ignore all attempts to refine this particular value and just
// always echo back a totally-unrefined DynamicVal.
return &RefinementBuilder{
orig: DynamicVal,
marks: marks,
}
case ty == String:
wip = &refinementString{}
case ty == Number:
@ -136,10 +146,27 @@ type RefinementBuilder struct {
wip unknownValRefinement
}
func (b *RefinementBuilder) assertRefineable() {
// refineable is an internal detail to help with two special situations
// related to refinements:
// - If the refinement is to a value of a type that doesn't support any
// refinements at all, this function will immediately panic with a
// message reporting that, because it's a caller bug to try to refine
// a value in a way that's inappropriate for its known type.
// - If the refinement is to an unknown value of an unknown type
// (i.e. cty.DynamicVal) then it returns false, indicating that the
// caller should just silently ignore whatever refinement was requested.
// - In all other cases this function returns true, which means the direct
// caller should attempt to apply the requested refinement, and then
// panic itself if the requested refinement doesn't make sense for the
// specific value being refined.
func (b *RefinementBuilder) refineable() bool {
if b.orig == DynamicVal {
return false
}
if b.wip == nil {
panic(fmt.Sprintf("cannot refine a %#v value", b.orig.Type()))
}
return true
}
// NotNull constrains the value as definitely not being null.
@ -157,7 +184,9 @@ func (b *RefinementBuilder) assertRefineable() {
// -- a value whose type is `cty.DynamicPseudoType` -- as being non-null.
// An unknown value of an unknown type is always completely unconstrained.
func (b *RefinementBuilder) NotNull() *RefinementBuilder {
b.assertRefineable()
if !b.refineable() {
return b
}
if b.orig.IsKnown() && b.orig.IsNull() {
panic("refining null value as non-null")
@ -181,7 +210,9 @@ func (b *RefinementBuilder) NotNull() *RefinementBuilder {
// value for each type constraint -- but this is here for symmetry with the
// fact that a [ValueRange] can also represent that a value is definitely null.
func (b *RefinementBuilder) Null() *RefinementBuilder {
b.assertRefineable()
if !b.refineable() {
return b
}
if b.orig.IsKnown() && !b.orig.IsNull() {
panic("refining non-null value as null")
@ -209,7 +240,9 @@ func (b *RefinementBuilder) NumberRangeInclusive(min, max Value) *RefinementBuil
// NumberRangeLowerBound constraints the lower bound of a number value, or
// panics if this builder is not refining a number value.
func (b *RefinementBuilder) NumberRangeLowerBound(min Value, inclusive bool) *RefinementBuilder {
b.assertRefineable()
if !b.refineable() {
return b
}
wip, ok := b.wip.(*refinementNumber)
if !ok {
@ -258,7 +291,9 @@ func (b *RefinementBuilder) NumberRangeLowerBound(min Value, inclusive bool) *Re
// NumberRangeUpperBound constraints the upper bound of a number value, or
// panics if this builder is not refining a number value.
func (b *RefinementBuilder) NumberRangeUpperBound(max Value, inclusive bool) *RefinementBuilder {
b.assertRefineable()
if !b.refineable() {
return b
}
wip, ok := b.wip.(*refinementNumber)
if !ok {
@ -308,7 +343,9 @@ func (b *RefinementBuilder) NumberRangeUpperBound(max Value, inclusive bool) *Re
// collection value, or panics if this builder is not refining a collection
// value.
func (b *RefinementBuilder) CollectionLengthLowerBound(min int) *RefinementBuilder {
b.assertRefineable()
if !b.refineable() {
return b
}
wip, ok := b.wip.(*refinementCollection)
if !ok {
@ -340,7 +377,9 @@ func (b *RefinementBuilder) CollectionLengthLowerBound(min int) *RefinementBuild
// The upper bound must be a known, non-null number or this function will
// panic.
func (b *RefinementBuilder) CollectionLengthUpperBound(max int) *RefinementBuilder {
b.assertRefineable()
if !b.refineable() {
return b
}
wip, ok := b.wip.(*refinementCollection)
if !ok {
@ -419,7 +458,9 @@ func (b *RefinementBuilder) StringPrefix(prefix string) *RefinementBuilder {
// Use [RefinementBuilder.StringPrefix] instead if an application cannot fully
// control the final result to avoid violating this rule.
func (b *RefinementBuilder) StringPrefixFull(prefix string) *RefinementBuilder {
b.assertRefineable()
if !b.refineable() {
return b
}
wip, ok := b.wip.(*refinementString)
if !ok {
@ -487,7 +528,7 @@ func (b *RefinementBuilder) NewValue() (ret Value) {
ret = ret.WithMarks(b.marks)
}()
if b.orig.IsKnown() {
if b.orig.IsKnown() || b.orig == DynamicVal {
return b.orig
}

View File

@ -21,6 +21,10 @@ import (
// offered by ranges and so can share code between both known and unknown
// values.
func (v Value) Range() ValueRange {
if v.IsMarked() {
panic("Value.Range on marked value; must be unmarked first")
}
// For an unknown value we just use its own refinements.
if unk, isUnk := v.v.(*unknownType); isUnk {
refinement := unk.refinement