diff options
author | Nathan Dench <ndenc2@gmail.com> | 2019-05-24 15:16:44 +1000 |
---|---|---|
committer | Nathan Dench <ndenc2@gmail.com> | 2019-05-24 15:16:44 +1000 |
commit | 107c1cdb09c575aa2f61d97f48d8587eb6bada4c (patch) | |
tree | ca7d008643efc555c388baeaf1d986e0b6b3e28c /vendor/github.com/zclconf/go-cty/cty/gocty | |
parent | 844b5a68d8af4791755b8f0ad293cc99f5959183 (diff) | |
download | terraform-provider-statuscake-107c1cdb09c575aa2f61d97f48d8587eb6bada4c.tar.gz terraform-provider-statuscake-107c1cdb09c575aa2f61d97f48d8587eb6bada4c.tar.zst terraform-provider-statuscake-107c1cdb09c575aa2f61d97f48d8587eb6bada4c.zip |
Upgrade to 0.12
Diffstat (limited to 'vendor/github.com/zclconf/go-cty/cty/gocty')
-rw-r--r-- | vendor/github.com/zclconf/go-cty/cty/gocty/in.go | 20 | ||||
-rw-r--r-- | vendor/github.com/zclconf/go-cty/cty/gocty/out.go | 41 |
2 files changed, 31 insertions, 30 deletions
diff --git a/vendor/github.com/zclconf/go-cty/cty/gocty/in.go b/vendor/github.com/zclconf/go-cty/cty/gocty/in.go index 642501b..ca9de21 100644 --- a/vendor/github.com/zclconf/go-cty/cty/gocty/in.go +++ b/vendor/github.com/zclconf/go-cty/cty/gocty/in.go | |||
@@ -5,6 +5,7 @@ import ( | |||
5 | "reflect" | 5 | "reflect" |
6 | 6 | ||
7 | "github.com/zclconf/go-cty/cty" | 7 | "github.com/zclconf/go-cty/cty" |
8 | "github.com/zclconf/go-cty/cty/convert" | ||
8 | "github.com/zclconf/go-cty/cty/set" | 9 | "github.com/zclconf/go-cty/cty/set" |
9 | ) | 10 | ) |
10 | 11 | ||
@@ -32,6 +33,11 @@ func ToCtyValue(val interface{}, ty cty.Type) (cty.Value, error) { | |||
32 | } | 33 | } |
33 | 34 | ||
34 | func toCtyValue(val reflect.Value, ty cty.Type, path cty.Path) (cty.Value, error) { | 35 | func toCtyValue(val reflect.Value, ty cty.Type, path cty.Path) (cty.Value, error) { |
36 | if val != (reflect.Value{}) && val.Type().AssignableTo(valueType) { | ||
37 | // If the source value is a cty.Value then we'll try to just pass | ||
38 | // through to the target type directly. | ||
39 | return toCtyPassthrough(val, ty, path) | ||
40 | } | ||
35 | 41 | ||
36 | switch ty { | 42 | switch ty { |
37 | case cty.Bool: | 43 | case cty.Bool: |
@@ -505,6 +511,20 @@ func toCtyDynamic(val reflect.Value, path cty.Path) (cty.Value, error) { | |||
505 | 511 | ||
506 | } | 512 | } |
507 | 513 | ||
514 | func toCtyPassthrough(wrappedVal reflect.Value, wantTy cty.Type, path cty.Path) (cty.Value, error) { | ||
515 | if wrappedVal = toCtyUnwrapPointer(wrappedVal); !wrappedVal.IsValid() { | ||
516 | return cty.NullVal(wantTy), nil | ||
517 | } | ||
518 | |||
519 | givenVal := wrappedVal.Interface().(cty.Value) | ||
520 | |||
521 | val, err := convert.Convert(givenVal, wantTy) | ||
522 | if err != nil { | ||
523 | return cty.NilVal, path.NewErrorf("unsuitable value: %s", err) | ||
524 | } | ||
525 | return val, nil | ||
526 | } | ||
527 | |||
508 | // toCtyUnwrapPointer is a helper for dealing with Go pointers. It has three | 528 | // toCtyUnwrapPointer is a helper for dealing with Go pointers. It has three |
509 | // possible outcomes: | 529 | // possible outcomes: |
510 | // | 530 | // |
diff --git a/vendor/github.com/zclconf/go-cty/cty/gocty/out.go b/vendor/github.com/zclconf/go-cty/cty/gocty/out.go index 99b65a7..e9c2599 100644 --- a/vendor/github.com/zclconf/go-cty/cty/gocty/out.go +++ b/vendor/github.com/zclconf/go-cty/cty/gocty/out.go | |||
@@ -1,11 +1,10 @@ | |||
1 | package gocty | 1 | package gocty |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "math" | ||
4 | "math/big" | 5 | "math/big" |
5 | "reflect" | 6 | "reflect" |
6 | 7 | ||
7 | "math" | ||
8 | |||
9 | "github.com/zclconf/go-cty/cty" | 8 | "github.com/zclconf/go-cty/cty" |
10 | ) | 9 | ) |
11 | 10 | ||
@@ -112,11 +111,7 @@ func fromCtyBool(val cty.Value, target reflect.Value, path cty.Path) error { | |||
112 | switch target.Kind() { | 111 | switch target.Kind() { |
113 | 112 | ||
114 | case reflect.Bool: | 113 | case reflect.Bool: |
115 | if val.True() { | 114 | target.SetBool(val.True()) |
116 | target.Set(reflect.ValueOf(true)) | ||
117 | } else { | ||
118 | target.Set(reflect.ValueOf(false)) | ||
119 | } | ||
120 | return nil | 115 | return nil |
121 | 116 | ||
122 | default: | 117 | default: |
@@ -175,8 +170,7 @@ func fromCtyNumberInt(bf *big.Float, target reflect.Value, path cty.Path) error | |||
175 | return path.NewErrorf("value must be a whole number, between %d and %d", min, max) | 170 | return path.NewErrorf("value must be a whole number, between %d and %d", min, max) |
176 | } | 171 | } |
177 | 172 | ||
178 | target.Set(reflect.ValueOf(iv).Convert(target.Type())) | 173 | target.SetInt(iv) |
179 | |||
180 | return nil | 174 | return nil |
181 | } | 175 | } |
182 | 176 | ||
@@ -202,25 +196,13 @@ func fromCtyNumberUInt(bf *big.Float, target reflect.Value, path cty.Path) error | |||
202 | return path.NewErrorf("value must be a whole number, between 0 and %d inclusive", max) | 196 | return path.NewErrorf("value must be a whole number, between 0 and %d inclusive", max) |
203 | } | 197 | } |
204 | 198 | ||
205 | target.Set(reflect.ValueOf(iv).Convert(target.Type())) | 199 | target.SetUint(iv) |
206 | |||
207 | return nil | 200 | return nil |
208 | } | 201 | } |
209 | 202 | ||
210 | func fromCtyNumberFloat(bf *big.Float, target reflect.Value, path cty.Path) error { | 203 | func fromCtyNumberFloat(bf *big.Float, target reflect.Value, path cty.Path) error { |
211 | switch target.Kind() { | 204 | switch target.Kind() { |
212 | case reflect.Float32: | 205 | case reflect.Float32, reflect.Float64: |
213 | fv, accuracy := bf.Float32() | ||
214 | if accuracy != big.Exact { | ||
215 | // We allow the precision to be truncated as part of our conversion, | ||
216 | // but we don't want to silently introduce infinities. | ||
217 | if math.IsInf(float64(fv), 0) { | ||
218 | return path.NewErrorf("value must be between %f and %f inclusive", -math.MaxFloat32, math.MaxFloat32) | ||
219 | } | ||
220 | } | ||
221 | target.Set(reflect.ValueOf(fv)) | ||
222 | return nil | ||
223 | case reflect.Float64: | ||
224 | fv, accuracy := bf.Float64() | 206 | fv, accuracy := bf.Float64() |
225 | if accuracy != big.Exact { | 207 | if accuracy != big.Exact { |
226 | // We allow the precision to be truncated as part of our conversion, | 208 | // 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 | |||
229 | return path.NewErrorf("value must be between %f and %f inclusive", -math.MaxFloat64, math.MaxFloat64) | 211 | return path.NewErrorf("value must be between %f and %f inclusive", -math.MaxFloat64, math.MaxFloat64) |
230 | } | 212 | } |
231 | } | 213 | } |
232 | target.Set(reflect.ValueOf(fv)) | 214 | target.SetFloat(fv) |
233 | return nil | 215 | return nil |
234 | default: | 216 | default: |
235 | panic("unsupported kind of float") | 217 | panic("unsupported kind of float") |
@@ -239,17 +221,17 @@ func fromCtyNumberFloat(bf *big.Float, target reflect.Value, path cty.Path) erro | |||
239 | func fromCtyNumberBig(bf *big.Float, target reflect.Value, path cty.Path) error { | 221 | func fromCtyNumberBig(bf *big.Float, target reflect.Value, path cty.Path) error { |
240 | switch { | 222 | switch { |
241 | 223 | ||
242 | case bigFloatType.AssignableTo(target.Type()): | 224 | case bigFloatType.ConvertibleTo(target.Type()): |
243 | // Easy! | 225 | // Easy! |
244 | target.Set(reflect.ValueOf(bf).Elem()) | 226 | target.Set(reflect.ValueOf(bf).Elem().Convert(target.Type())) |
245 | return nil | 227 | return nil |
246 | 228 | ||
247 | case bigIntType.AssignableTo(target.Type()): | 229 | case bigIntType.ConvertibleTo(target.Type()): |
248 | bi, accuracy := bf.Int(nil) | 230 | bi, accuracy := bf.Int(nil) |
249 | if accuracy != big.Exact { | 231 | if accuracy != big.Exact { |
250 | return path.NewErrorf("value must be a whole number") | 232 | return path.NewErrorf("value must be a whole number") |
251 | } | 233 | } |
252 | target.Set(reflect.ValueOf(bi).Elem()) | 234 | target.Set(reflect.ValueOf(bi).Elem().Convert(target.Type())) |
253 | return nil | 235 | return nil |
254 | 236 | ||
255 | default: | 237 | default: |
@@ -259,9 +241,8 @@ func fromCtyNumberBig(bf *big.Float, target reflect.Value, path cty.Path) error | |||
259 | 241 | ||
260 | func fromCtyString(val cty.Value, target reflect.Value, path cty.Path) error { | 242 | func fromCtyString(val cty.Value, target reflect.Value, path cty.Path) error { |
261 | switch target.Kind() { | 243 | switch target.Kind() { |
262 | |||
263 | case reflect.String: | 244 | case reflect.String: |
264 | target.Set(reflect.ValueOf(val.AsString())) | 245 | target.SetString(val.AsString()) |
265 | return nil | 246 | return nil |
266 | 247 | ||
267 | default: | 248 | default: |