vendor: go get github.com/zclconf/go-cty@master

This includes a more comprehensive implementation of Value.GoString, along
with various other changes that don't affect Terraform.
This commit is contained in:
Martin Atkins 2019-04-24 17:07:30 -07:00
parent b7705d20a0
commit 95e5ef13a7
8 changed files with 70 additions and 44 deletions

2
go.mod
View File

@ -107,7 +107,7 @@ require (
github.com/xanzy/ssh-agent v0.2.1
github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18 // indirect
github.com/xlab/treeprint v0.0.0-20161029104018-1d6e34225557
github.com/zclconf/go-cty v0.0.0-20190320224746-fd76348b9329
github.com/zclconf/go-cty v0.0.0-20190425000443-8c00057b05d7
go.uber.org/atomic v1.3.2 // indirect
go.uber.org/multierr v1.1.0 // indirect
go.uber.org/zap v1.9.1 // indirect

4
go.sum
View File

@ -401,8 +401,8 @@ github.com/xlab/treeprint v0.0.0-20161029104018-1d6e34225557/go.mod h1:ce1O1j6Ut
github.com/zclconf/go-cty v0.0.0-20181129180422-88fbe721e0f8/go.mod h1:xnAOWiHeOqg2nWS62VtQ7pbOu17FtxJNW8RLEih+O3s=
github.com/zclconf/go-cty v0.0.0-20190124225737-a385d646c1e9 h1:hHCAGde+QfwbqXSAqOmBd4NlOrJ6nmjWp+Nu408ezD4=
github.com/zclconf/go-cty v0.0.0-20190124225737-a385d646c1e9/go.mod h1:xnAOWiHeOqg2nWS62VtQ7pbOu17FtxJNW8RLEih+O3s=
github.com/zclconf/go-cty v0.0.0-20190320224746-fd76348b9329 h1:ne520NlvoncW5zfBGkmP4EJhyd6ruSaSyhzobv0Vz9w=
github.com/zclconf/go-cty v0.0.0-20190320224746-fd76348b9329/go.mod h1:xnAOWiHeOqg2nWS62VtQ7pbOu17FtxJNW8RLEih+O3s=
github.com/zclconf/go-cty v0.0.0-20190425000443-8c00057b05d7 h1:GppzGMnuVhCyg/BNYMI39tu1peZ1E/XVg+ZsLUyNdhk=
github.com/zclconf/go-cty v0.0.0-20190425000443-8c00057b05d7/go.mod h1:xnAOWiHeOqg2nWS62VtQ7pbOu17FtxJNW8RLEih+O3s=
go.opencensus.io v0.18.0 h1:Mk5rgZcggtbvtAun5aJzAtjKKN/t0R3jJPlWILlv938=
go.opencensus.io v0.18.0/go.mod h1:vKdFvxhtzZ9onBp9VKHK8z/sRpBMnKAsufL7wlDrCOA=
go.uber.org/atomic v1.3.2 h1:2Oa65PReHzfn29GpvgsYwloV9AVFHPDk8tYxt2c2tr4=

View File

@ -1070,7 +1070,7 @@ func TestAssertObjectCompatible(t *testing.T) {
}),
}),
[]string{
`.block: planned set element cty.Value{ty: cty.Object(map[string]cty.Type{"foo":cty.String}), v: map[string]interface {}{"foo":"hello"}} does not correlate with any element in actual`,
`.block: planned set element cty.ObjectVal(map[string]cty.Value{"foo":cty.StringVal("hello")}) does not correlate with any element in actual`,
},
},
{

View File

@ -1,11 +1,10 @@
package gocty
import (
"math"
"math/big"
"reflect"
"math"
"github.com/zclconf/go-cty/cty"
)
@ -112,11 +111,7 @@ func fromCtyBool(val cty.Value, target reflect.Value, path cty.Path) error {
switch target.Kind() {
case reflect.Bool:
if val.True() {
target.Set(reflect.ValueOf(true))
} else {
target.Set(reflect.ValueOf(false))
}
target.SetBool(val.True())
return nil
default:
@ -175,8 +170,7 @@ func fromCtyNumberInt(bf *big.Float, target reflect.Value, path cty.Path) error
return path.NewErrorf("value must be a whole number, between %d and %d", min, max)
}
target.Set(reflect.ValueOf(iv).Convert(target.Type()))
target.SetInt(iv)
return nil
}
@ -202,25 +196,13 @@ func fromCtyNumberUInt(bf *big.Float, target reflect.Value, path cty.Path) error
return path.NewErrorf("value must be a whole number, between 0 and %d inclusive", max)
}
target.Set(reflect.ValueOf(iv).Convert(target.Type()))
target.SetUint(iv)
return nil
}
func fromCtyNumberFloat(bf *big.Float, target reflect.Value, path cty.Path) error {
switch target.Kind() {
case reflect.Float32:
fv, accuracy := bf.Float32()
if accuracy != big.Exact {
// We allow the precision to be truncated as part of our conversion,
// but we don't want to silently introduce infinities.
if math.IsInf(float64(fv), 0) {
return path.NewErrorf("value must be between %f and %f inclusive", -math.MaxFloat32, math.MaxFloat32)
}
}
target.Set(reflect.ValueOf(fv))
return nil
case reflect.Float64:
case reflect.Float32, reflect.Float64:
fv, accuracy := bf.Float64()
if accuracy != big.Exact {
// We allow the precision to be truncated as part of our conversion,
@ -229,7 +211,7 @@ func fromCtyNumberFloat(bf *big.Float, target reflect.Value, path cty.Path) erro
return path.NewErrorf("value must be between %f and %f inclusive", -math.MaxFloat64, math.MaxFloat64)
}
}
target.Set(reflect.ValueOf(fv))
target.SetFloat(fv)
return nil
default:
panic("unsupported kind of float")
@ -239,17 +221,17 @@ func fromCtyNumberFloat(bf *big.Float, target reflect.Value, path cty.Path) erro
func fromCtyNumberBig(bf *big.Float, target reflect.Value, path cty.Path) error {
switch {
case bigFloatType.AssignableTo(target.Type()):
case bigFloatType.ConvertibleTo(target.Type()):
// Easy!
target.Set(reflect.ValueOf(bf).Elem())
target.Set(reflect.ValueOf(bf).Elem().Convert(target.Type()))
return nil
case bigIntType.AssignableTo(target.Type()):
case bigIntType.ConvertibleTo(target.Type()):
bi, accuracy := bf.Int(nil)
if accuracy != big.Exact {
return path.NewErrorf("value must be a whole number")
}
target.Set(reflect.ValueOf(bi).Elem())
target.Set(reflect.ValueOf(bi).Elem().Convert(target.Type()))
return nil
default:
@ -259,9 +241,8 @@ func fromCtyNumberBig(bf *big.Float, target reflect.Value, path cty.Path) error
func fromCtyString(val cty.Value, target reflect.Value, path cty.Path) error {
switch target.Kind() {
case reflect.String:
target.Set(reflect.ValueOf(val.AsString()))
target.SetString(val.AsString())
return nil
default:

View File

@ -51,6 +51,11 @@ func (p Path) Index(v Value) Path {
return ret
}
// IndexPath is a convenience method to start a new Path with an IndexStep.
func IndexPath(v Value) Path {
return Path{}.Index(v)
}
// GetAttr returns a new Path that is the reciever with a GetAttrStep appended
// to the end.
//
@ -66,6 +71,11 @@ func (p Path) GetAttr(name string) Path {
return ret
}
// GetAttrPath is a convenience method to start a new Path with a GetAttrStep.
func GetAttrPath(name string) Path {
return Path{}.GetAttr(name)
}
// Apply applies each of the steps in turn to successive values starting with
// the given value, and returns the result. If any step returns an error,
// the whole operation returns an error.

View File

@ -56,6 +56,18 @@ func ParseNumberVal(s string) (Value, error) {
return NumberVal(f), nil
}
// MustParseNumberVal is like ParseNumberVal but it will panic in case of any
// error. It can be used during initialization or any other situation where
// the given string is a constant or otherwise known to be correct by the
// caller.
func MustParseNumberVal(s string) Value {
ret, err := ParseNumberVal(s)
if err != nil {
panic(err)
}
return ret
}
// NumberIntVal returns a Value of type Number whose internal value is equal
// to the given integer.
func NumberIntVal(v int64) Value {

View File

@ -3,12 +3,13 @@ package cty
import (
"fmt"
"math/big"
"reflect"
"github.com/zclconf/go-cty/cty/set"
)
// GoString is an implementation of fmt.GoStringer that produces concise
// source-like representations of values suitable for use in debug messages.
func (val Value) GoString() string {
if val == NilVal {
return "cty.NilVal"
@ -32,9 +33,8 @@ func (val Value) GoString() string {
case Bool:
if val.v.(bool) {
return "cty.True"
} else {
return "cty.False"
}
return "cty.False"
case Number:
fv := val.v.(*big.Float)
// We'll try to use NumberIntVal or NumberFloatVal if we can, since
@ -45,19 +45,42 @@ func (val Value) GoString() string {
if rfv, accuracy := fv.Float64(); accuracy == big.Exact {
return fmt.Sprintf("cty.NumberFloatVal(%#v)", rfv)
}
return fmt.Sprintf("cty.NumberVal(new(big.Float).Parse(\"%#v\", 10))", fv)
return fmt.Sprintf("cty.MustParseNumberVal(%q)", fv.Text('f', -1))
case String:
return fmt.Sprintf("cty.StringVal(%#v)", val.v)
}
switch {
case val.ty.IsSetType():
vals := val.v.(set.Set).Values()
if vals == nil || len(vals) == 0 {
return fmt.Sprintf("cty.SetValEmpty()")
} else {
return fmt.Sprintf("cty.SetVal(%#v)", vals)
vals := val.AsValueSlice()
if len(vals) == 0 {
return fmt.Sprintf("cty.SetValEmpty(%#v)", val.ty.ElementType())
}
return fmt.Sprintf("cty.SetVal(%#v)", vals)
case val.ty.IsListType():
vals := val.AsValueSlice()
if len(vals) == 0 {
return fmt.Sprintf("cty.ListValEmpty(%#v)", val.ty.ElementType())
}
return fmt.Sprintf("cty.ListVal(%#v)", vals)
case val.ty.IsMapType():
vals := val.AsValueMap()
if len(vals) == 0 {
return fmt.Sprintf("cty.MapValEmpty(%#v)", val.ty.ElementType())
}
return fmt.Sprintf("cty.MapVal(%#v)", vals)
case val.ty.IsTupleType():
if val.ty.Equals(EmptyTuple) {
return "cty.EmptyTupleVal"
}
vals := val.AsValueSlice()
return fmt.Sprintf("cty.TupleVal(%#v)", vals)
case val.ty.IsObjectType():
if val.ty.Equals(EmptyObject) {
return "cty.EmptyObjectVal"
}
vals := val.AsValueMap()
return fmt.Sprintf("cty.ObjectVal(%#v)", vals)
case val.ty.IsCapsuleType():
return fmt.Sprintf("cty.CapsuleVal(%#v, %#v)", val.ty, val.v)
}

2
vendor/modules.txt vendored
View File

@ -434,7 +434,7 @@ github.com/vmihailenco/msgpack/codes
github.com/xanzy/ssh-agent
# github.com/xlab/treeprint v0.0.0-20161029104018-1d6e34225557
github.com/xlab/treeprint
# github.com/zclconf/go-cty v0.0.0-20190320224746-fd76348b9329
# github.com/zclconf/go-cty v0.0.0-20190425000443-8c00057b05d7
github.com/zclconf/go-cty/cty
github.com/zclconf/go-cty/cty/gocty
github.com/zclconf/go-cty/cty/convert