aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/zclconf/go-cty/cty/gocty/in.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/zclconf/go-cty/cty/gocty/in.go')
-rw-r--r--vendor/github.com/zclconf/go-cty/cty/gocty/in.go20
1 files changed, 20 insertions, 0 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
34func toCtyValue(val reflect.Value, ty cty.Type, path cty.Path) (cty.Value, error) { 35func 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
514func 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//