From f8a8f26c0db56ba44ed0c9b70913fd3d1fa1162d Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Wed, 23 May 2018 17:38:51 -0700 Subject: [PATCH] govendor fetch github.com/zclconf/go-cty/cty/... This includes upstream fixes, and in particular a converter for going between map types with different element types. --- .../zclconf/go-cty/cty/convert/conversion.go | 9 ++++ .../cty/convert/conversion_collection.go | 44 +++++++++++++++++++ .../go-cty/cty/function/stdlib/format_fsm.go | 2 +- .../go-cty/cty/function/stdlib/format_fsm.rl | 2 +- vendor/vendor.json | 32 +++++++------- 5 files changed, 71 insertions(+), 18 deletions(-) diff --git a/vendor/github.com/zclconf/go-cty/cty/convert/conversion.go b/vendor/github.com/zclconf/go-cty/cty/convert/conversion.go index 7bfcc081cc..8afdc727cc 100644 --- a/vendor/github.com/zclconf/go-cty/cty/convert/conversion.go +++ b/vendor/github.com/zclconf/go-cty/cty/convert/conversion.go @@ -93,6 +93,15 @@ func getConversionKnown(in cty.Type, out cty.Type, unsafe bool) conversion { } return conversionCollectionToSet(outEty, convEty) + case out.IsMapType() && in.IsMapType(): + inEty := in.ElementType() + outEty := out.ElementType() + convEty := getConversion(inEty, outEty, unsafe) + if convEty == nil { + return nil + } + return conversionCollectionToMap(outEty, convEty) + case out.IsListType() && in.IsTupleType(): outEty := out.ElementType() return conversionTupleToList(in, outEty, unsafe) diff --git a/vendor/github.com/zclconf/go-cty/cty/convert/conversion_collection.go b/vendor/github.com/zclconf/go-cty/cty/convert/conversion_collection.go index eace85d3dd..a157b0bf82 100644 --- a/vendor/github.com/zclconf/go-cty/cty/convert/conversion_collection.go +++ b/vendor/github.com/zclconf/go-cty/cty/convert/conversion_collection.go @@ -84,6 +84,50 @@ func conversionCollectionToSet(ety cty.Type, conv conversion) conversion { } } +// conversionCollectionToMap returns a conversion that will apply the given +// conversion to all of the elements of a collection (something that supports +// ForEachElement and LengthInt) and then returns the result as a map. +// +// "conv" can be nil if the elements are expected to already be of the +// correct type and just need to be re-wrapped into a map. +func conversionCollectionToMap(ety cty.Type, conv conversion) conversion { + return func(val cty.Value, path cty.Path) (cty.Value, error) { + elems := make(map[string]cty.Value, 0) + path = append(path, nil) + it := val.ElementIterator() + for it.Next() { + key, val := it.Element() + var err error + + path[len(path)-1] = cty.IndexStep{ + Key: key, + } + + keyStr, err := Convert(key, cty.String) + if err != nil { + // Should never happen, because keys can only be numbers or + // strings and both can convert to string. + return cty.DynamicVal, path.NewErrorf("cannot convert key type %s to string for map", key.Type().FriendlyName()) + } + + if conv != nil { + val, err = conv(val, path) + if err != nil { + return cty.NilVal, err + } + } + + elems[keyStr.AsString()] = val + } + + if len(elems) == 0 { + return cty.MapValEmpty(ety), nil + } + + return cty.MapVal(elems), nil + } +} + // conversionTupleToList returns a conversion that will take a value of the // given tuple type and return a list of the given element type. // diff --git a/vendor/github.com/zclconf/go-cty/cty/function/stdlib/format_fsm.go b/vendor/github.com/zclconf/go-cty/cty/function/stdlib/format_fsm.go index 86876ba9fe..1dc1f4610d 100644 --- a/vendor/github.com/zclconf/go-cty/cty/function/stdlib/format_fsm.go +++ b/vendor/github.com/zclconf/go-cty/cty/function/stdlib/format_fsm.go @@ -351,7 +351,7 @@ func formatFSM(format string, a []cty.Value) (string, error) { // be impossible (the scanner matches all bytes _somehow_) but we'll // flag it anyway rather than just losing data from the end. if cs < formatfsm_first_final { - return buf.String(), fmt.Errorf("extraneous characters beginning at offset %i", p) + return buf.String(), fmt.Errorf("extraneous characters beginning at offset %d", p) } return buf.String(), nil diff --git a/vendor/github.com/zclconf/go-cty/cty/function/stdlib/format_fsm.rl b/vendor/github.com/zclconf/go-cty/cty/function/stdlib/format_fsm.rl index 85d43bb77f..dbaa91c6b0 100644 --- a/vendor/github.com/zclconf/go-cty/cty/function/stdlib/format_fsm.rl +++ b/vendor/github.com/zclconf/go-cty/cty/function/stdlib/format_fsm.rl @@ -175,7 +175,7 @@ func formatFSM(format string, a []cty.Value) (string, error) { // be impossible (the scanner matches all bytes _somehow_) but we'll // flag it anyway rather than just losing data from the end. if cs < formatfsm_first_final { - return buf.String(), fmt.Errorf("extraneous characters beginning at offset %i", p) + return buf.String(), fmt.Errorf("extraneous characters beginning at offset %d", p) } return buf.String(), nil diff --git a/vendor/vendor.json b/vendor/vendor.json index 60f7ecc469..8034b37bc5 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -2430,44 +2430,44 @@ { "checksumSHA1": "4REWNRi5Dg7Kxj1US72+/oVii3Q=", "path": "github.com/zclconf/go-cty/cty", - "revision": "b7d1e828d86e99040528ce06ce970382c7813f96", - "revisionTime": "2018-03-26T23:07:54Z" + "revision": "ba988ce11d9994867838957d4c40bb1ad78b433d", + "revisionTime": "2018-05-24T00:26:36Z" }, { - "checksumSHA1": "gDpi8g5VxCRM3JKm/kaYlGdFUdQ=", + "checksumSHA1": "g3pPIVGKkD4gt8TasyLxSX+qdP0=", "path": "github.com/zclconf/go-cty/cty/convert", - "revision": "b7d1e828d86e99040528ce06ce970382c7813f96", - "revisionTime": "2018-03-26T23:07:54Z" + "revision": "ba988ce11d9994867838957d4c40bb1ad78b433d", + "revisionTime": "2018-05-24T00:26:36Z" }, { "checksumSHA1": "MyyLCGg3RREMllTJyK6ehZl/dHk=", "path": "github.com/zclconf/go-cty/cty/function", - "revision": "b7d1e828d86e99040528ce06ce970382c7813f96", - "revisionTime": "2018-03-26T23:07:54Z" + "revision": "ba988ce11d9994867838957d4c40bb1ad78b433d", + "revisionTime": "2018-05-24T00:26:36Z" }, { - "checksumSHA1": "4R+DQqBew6i9a4lYiLZW1OXVwTI=", + "checksumSHA1": "kcTJOuL131/stXJ4U9tC3SASQLs=", "path": "github.com/zclconf/go-cty/cty/function/stdlib", - "revision": "b7d1e828d86e99040528ce06ce970382c7813f96", - "revisionTime": "2018-03-26T23:07:54Z" + "revision": "ba988ce11d9994867838957d4c40bb1ad78b433d", + "revisionTime": "2018-05-24T00:26:36Z" }, { "checksumSHA1": "tmCzwfNXOEB1sSO7TKVzilb2vjA=", "path": "github.com/zclconf/go-cty/cty/gocty", - "revision": "b7d1e828d86e99040528ce06ce970382c7813f96", - "revisionTime": "2018-03-26T23:07:54Z" + "revision": "ba988ce11d9994867838957d4c40bb1ad78b433d", + "revisionTime": "2018-05-24T00:26:36Z" }, { "checksumSHA1": "1ApmO+Q33+Oem/3f6BU6sztJWNc=", "path": "github.com/zclconf/go-cty/cty/json", - "revision": "b7d1e828d86e99040528ce06ce970382c7813f96", - "revisionTime": "2018-03-26T23:07:54Z" + "revision": "ba988ce11d9994867838957d4c40bb1ad78b433d", + "revisionTime": "2018-05-24T00:26:36Z" }, { "checksumSHA1": "y5Sk+n6SOspFj8mlyb8swr4DMIs=", "path": "github.com/zclconf/go-cty/cty/set", - "revision": "b7d1e828d86e99040528ce06ce970382c7813f96", - "revisionTime": "2018-03-26T23:07:54Z" + "revision": "ba988ce11d9994867838957d4c40bb1ad78b433d", + "revisionTime": "2018-05-24T00:26:36Z" }, { "checksumSHA1": "vE43s37+4CJ2CDU6TlOUOYE0K9c=",