Fix panic when traversing marked map value

This commit is contained in:
Alisdair McDiarmid 2020-09-24 12:40:41 -04:00
parent 4997e114f6
commit 35ad93007d
2 changed files with 15 additions and 1 deletions

7
ops.go
View File

@ -217,7 +217,12 @@ func GetAttr(obj cty.Value, attrName string, srcRange *Range) (cty.Value, Diagno
}
idx := cty.StringVal(attrName)
if obj.HasIndex(idx).False() {
// Here we drop marks from HasIndex result, in order to allow basic
// traversal of a marked map in the same way we can traverse a marked
// object
hasIndex, _ := obj.HasIndex(idx).Unmark()
if hasIndex.False() {
return cty.DynamicVal, Diagnostics{
{
Severity: DiagError,

View File

@ -48,6 +48,15 @@ func TestApplyPath(t *testing.T) {
cty.StringVal("hello"),
``,
},
{
cty.MapVal(map[string]cty.Value{
"a": cty.StringVal("foo").Mark("x"),
"b": cty.StringVal("bar").Mark("x"),
}).Mark("x"),
cty.GetAttrPath("a"),
cty.StringVal("foo").Mark("x"),
``,
},
{
cty.ListValEmpty(cty.String),
(cty.Path)(nil).Index(cty.NumberIntVal(0)),