diff options
Diffstat (limited to 'vendor/github.com/zclconf/go-cty/cty/gocty/out.go')
-rw-r--r-- | vendor/github.com/zclconf/go-cty/cty/gocty/out.go | 41 |
1 files changed, 11 insertions, 30 deletions
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: |