Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tftypes: Change (AttributePath).WithElementKeyInt() method parameter to int #101

Merged
merged 5 commits into from
Aug 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/101.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:breaking-change
tftypes: `(AttributePath).WithElementKeyInt()` now has an `int` parameter instead of `int64`. Using `(AttributePath).WithElementKeyInt()` within `for ... range` loops no longer requires `int64()` conversion.
```
2 changes: 1 addition & 1 deletion tftypes/attribute_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (a *AttributePath) WithElementKeyString(key string) *AttributePath {

// WithElementKeyInt adds an ElementKeyInt step to `a`, using `key` as the
// element's key. `a` is copied, not modified.
func (a *AttributePath) WithElementKeyInt(key int64) *AttributePath {
func (a *AttributePath) WithElementKeyInt(key int) *AttributePath {
steps := a.Steps()
return &AttributePath{
steps: append(steps, ElementKeyInt(key)),
Expand Down
4 changes: 2 additions & 2 deletions tftypes/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ func valueFromList(typ Type, in interface{}) (Value, error) {
var valType Type
for pos, v := range value {
if v.Type().Is(DynamicPseudoType) && v.IsKnown() {
return Value{}, NewAttributePath().WithElementKeyInt(int64(pos)).NewErrorf("invalid value %s for %s", v, v.Type())
return Value{}, NewAttributePath().WithElementKeyInt(pos).NewErrorf("invalid value %s for %s", v, v.Type())
} else if !v.Type().Is(DynamicPseudoType) && !v.Type().UsableAs(typ) {
return Value{}, NewAttributePath().WithElementKeyInt(int64(pos)).NewErrorf("can't use %s as %s", v.Type(), typ)
return Value{}, NewAttributePath().WithElementKeyInt(pos).NewErrorf("can't use %s as %s", v.Type(), typ)
}
if valType == nil {
valType = v.Type()
Expand Down
4 changes: 2 additions & 2 deletions tftypes/tuple.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ func valueFromTuple(types []Type, in interface{}) (Value, error) {
for pos, v := range value {
typ := types[pos]
if v.Type().Is(DynamicPseudoType) && v.IsKnown() {
return Value{}, NewAttributePath().WithElementKeyInt(int64(pos)).NewErrorf("invalid value %s for %s", v, v.Type())
return Value{}, NewAttributePath().WithElementKeyInt(pos).NewErrorf("invalid value %s for %s", v, v.Type())
} else if !v.Type().Is(DynamicPseudoType) && !v.Type().UsableAs(typ) {
return Value{}, NewAttributePath().WithElementKeyInt(int64(pos)).NewErrorf("can't use %s as %s", v.Type(), typ)
return Value{}, NewAttributePath().WithElementKeyInt(pos).NewErrorf("can't use %s as %s", v.Type(), typ)
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions tftypes/value_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func jsonUnmarshalList(buf []byte, elementType Type, p *AttributePath) (Value, e
// distinction, so we'll allow it.
vals := []Value{}

var idx int64
var idx int
for dec.More() {
innerPath := p.WithElementKeyInt(idx)
// update the index
Expand Down Expand Up @@ -396,9 +396,9 @@ func jsonUnmarshalTuple(buf []byte, elementTypes []Type, p *AttributePath) (Valu
types := []Type{}
vals := []Value{}

var idx int64
var idx int
for dec.More() {
if idx >= int64(len(elementTypes)) {
if idx >= len(elementTypes) {
return Value{}, p.NewErrorf("too many tuple elements (only have types for %d)", len(elementTypes))
}

Expand Down
10 changes: 5 additions & 5 deletions tftypes/value_msgpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func msgpackUnmarshalList(dec *msgpack.Decoder, typ Type, path *AttributePath) (

vals := make([]Value, 0, length)
for i := 0; i < length; i++ {
innerPath := path.WithElementKeyInt(int64(i))
innerPath := path.WithElementKeyInt(i)
val, err := msgpackUnmarshal(dec, typ, innerPath)
if err != nil {
return Value{}, err
Expand Down Expand Up @@ -190,7 +190,7 @@ func msgpackUnmarshalSet(dec *msgpack.Decoder, typ Type, path *AttributePath) (V

vals := make([]Value, 0, length)
for i := 0; i < length; i++ {
innerPath := path.WithElementKeyInt(int64(i))
innerPath := path.WithElementKeyInt(i)
val, err := msgpackUnmarshal(dec, typ, innerPath)
if err != nil {
return Value{}, err
Expand Down Expand Up @@ -278,7 +278,7 @@ func msgpackUnmarshalTuple(dec *msgpack.Decoder, types []Type, path *AttributePa
elTypes := make([]Type, 0, length)
vals := make([]Value, 0, length)
for i := 0; i < length; i++ {
innerPath := path.WithElementKeyInt(int64(i))
innerPath := path.WithElementKeyInt(i)
typ := types[i]
val, err := msgpackUnmarshal(dec, typ, innerPath)
if err != nil {
Expand Down Expand Up @@ -489,7 +489,7 @@ func marshalMsgPackList(val Value, typ Type, p *AttributePath, enc *msgpack.Enco
return p.NewErrorf("error encoding list length: %w", err)
}
for pos, i := range l {
err := marshalMsgPack(i, typ.(List).ElementType, p.WithElementKeyInt(int64(pos)), enc)
err := marshalMsgPack(i, typ.(List).ElementType, p.WithElementKeyInt(pos), enc)
if err != nil {
return err
}
Expand Down Expand Up @@ -549,7 +549,7 @@ func marshalMsgPackTuple(val Value, typ Type, p *AttributePath, enc *msgpack.Enc
}
for pos, v := range t {
ty := types[pos]
err := marshalMsgPack(v, ty, p.WithElementKeyInt(int64(pos)), enc)
err := marshalMsgPack(v, ty, p.WithElementKeyInt(pos), enc)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions tftypes/walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func walk(path *AttributePath, val Value, cb func(*AttributePath, Value) (bool,
if ty.Is(Set{}) {
path = path.WithElementKeyValue(el)
} else {
path = path.WithElementKeyInt(int64(pos))
path = path.WithElementKeyInt(pos)
}
err = walk(path, el, cb)
if err != nil {
Expand Down Expand Up @@ -133,7 +133,7 @@ func transform(path *AttributePath, val Value, cb func(*AttributePath, Value) (V
if ty.Is(Set{}) {
path = path.WithElementKeyValue(el)
} else {
path = path.WithElementKeyInt(int64(pos))
path = path.WithElementKeyInt(pos)
}
newEl, err := transform(path, el, cb)
if err != nil {
Expand Down