lang: Fix crash in lookup function

This commit is contained in:
Radek Simko 2018-10-22 12:58:47 +02:00
parent 1dc3e50c47
commit 4856d81300
No known key found for this signature in database
GPG Key ID: 1F1C84FE689A88D7
2 changed files with 25 additions and 1 deletions

View File

@ -512,9 +512,14 @@ var LookupFunc = function.New(&function.Spec{
}
ty := args[0].Type()
key := args[1].AsString()
switch {
case ty.IsObjectType():
if !args[1].IsKnown() {
return args[2].Type(), nil
}
key := args[1].AsString()
if ty.HasAttribute(key) {
return args[0].GetAttr(key).Type(), nil
} else if len(args) == 3 {

View File

@ -1255,6 +1255,25 @@ func TestLookup(t *testing.T) {
cty.UnknownVal(cty.String),
false,
},
{
[]cty.Value{
simpleMap,
cty.UnknownVal(cty.String),
},
cty.UnknownVal(cty.String),
false,
},
{
[]cty.Value{
cty.ObjectVal(map[string]cty.Value{
"foo": cty.StringVal("a"),
"bar": cty.StringVal("b"),
}),
cty.UnknownVal(cty.String),
},
cty.UnknownVal(cty.String),
false,
},
}
for _, test := range tests {