mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-09 21:17:09 +08:00
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:
49
vendor/github.com/zclconf/go-cty/cty/function/function.go
generated
vendored
49
vendor/github.com/zclconf/go-cty/cty/function/function.go
generated
vendored
@ -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
|
||||
|
Reference in New Issue
Block a user