mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-08 15:13:56 -06:00
Merge pull request #19161 from hashicorp/b-lookup-crash-fix
lang: Fix crash in lookup function
This commit is contained in:
commit
1de7c5849d
@ -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 cty.DynamicPseudoType, nil
|
||||
}
|
||||
|
||||
key := args[1].AsString()
|
||||
if ty.HasAttribute(key) {
|
||||
return args[0].GetAttr(key).Type(), nil
|
||||
} else if len(args) == 3 {
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user