From d0cb134fec46161a39550b3a2639bb09fc9ea706 Mon Sep 17 00:00:00 2001 From: Alisdair McDiarmid Date: Thu, 26 Nov 2020 10:59:16 -0500 Subject: [PATCH] Fix panic traversing marked list We need to unmark the result of HasIndex in order to compare it with true or false without a panic. --- ops.go | 5 ++++- ops_test.go | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ops.go b/ops.go index 20c8039..f69de5b 100644 --- a/ops.go +++ b/ops.go @@ -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 diff --git a/ops_test.go b/ops_test.go index 39b748f..82eee9b 100644 --- a/ops_test.go +++ b/ops_test.go @@ -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"),