Merge pull request #424 from hashicorp/alisdair/fix-panic-traversing-marked-list

Fix panic traversing marked list
This commit is contained in:
Alisdair McDiarmid 2020-11-30 11:08:39 -05:00 committed by GitHub
commit 2aa4aecdba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

5
ops.go
View File

@ -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

View File

@ -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"),