Skip to content

Commit

Permalink
Fix panic traversing marked list
Browse files Browse the repository at this point in the history
We need to unmark the result of HasIndex in order to compare it with
true or false without a panic.
  • Loading branch information
alisdair committed Nov 26, 2020
1 parent 3bb0644 commit d0cb134
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ func Index(collection, key cty.Value, srcRange *Range) (cty.Value, Diagnostics)
}
}

has := collection.HasIndex(key)
// Here we drop marks from HasIndex result, in order to allow basic
// traversal of a marked list, tuple, or map in the same way we can
// traverse a marked object
has, _ := collection.HasIndex(key).Unmark()
if !has.IsKnown() {
if ty.IsTupleType() {
return cty.DynamicVal, nil
Expand Down
8 changes: 8 additions & 0 deletions ops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ func TestApplyPath(t *testing.T) {
cty.StringVal("hello"),
``,
},
{
cty.ListVal([]cty.Value{
cty.StringVal("hello"),
}).Mark("x"),
(cty.Path)(nil).Index(cty.NumberIntVal(0)),
cty.StringVal("hello").Mark("x"),
``,
},
{
cty.TupleVal([]cty.Value{
cty.StringVal("hello"),
Expand Down

0 comments on commit d0cb134

Please sign in to comment.