Fix panic when traversing marked map value
This commit is contained in:
parent
4997e114f6
commit
35ad93007d
7
ops.go
7
ops.go
@ -217,7 +217,12 @@ func GetAttr(obj cty.Value, attrName string, srcRange *Range) (cty.Value, Diagno
|
|||||||
}
|
}
|
||||||
|
|
||||||
idx := cty.StringVal(attrName)
|
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{
|
return cty.DynamicVal, Diagnostics{
|
||||||
{
|
{
|
||||||
Severity: DiagError,
|
Severity: DiagError,
|
||||||
|
@ -48,6 +48,15 @@ func TestApplyPath(t *testing.T) {
|
|||||||
cty.StringVal("hello"),
|
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.ListValEmpty(cty.String),
|
||||||
(cty.Path)(nil).Index(cty.NumberIntVal(0)),
|
(cty.Path)(nil).Index(cty.NumberIntVal(0)),
|
||||||
|
Loading…
Reference in New Issue
Block a user