Skip to content

Commit

Permalink
function/stdlib: Allow empty maps in merge function
Browse files Browse the repository at this point in the history
  • Loading branch information
pselle authored Jun 23, 2020
1 parent 98cf8ce commit edc8e82
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cty/function/stdlib/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,9 @@ var MergeFunc = function.New(&function.Spec{
case allNull:
return cty.NullVal(retType), nil
case retType.IsMapType():
if len(outputMap) == 0 {
return cty.MapValEmpty(retType.ElementType()), nil
}
return cty.MapVal(outputMap), nil
case retType.IsObjectType(), retType.Equals(cty.DynamicPseudoType):
return cty.ObjectVal(outputMap), nil
Expand Down
8 changes: 8 additions & 0 deletions cty/function/stdlib/collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,14 @@ func TestMerge(t *testing.T) {
cty.NilVal,
true,
},
{ // Empty maps are allowed in merge
[]cty.Value{
cty.MapValEmpty(cty.String),
cty.MapValEmpty(cty.String),
},
cty.MapValEmpty(cty.String),
false,
},
}

for _, test := range tests {
Expand Down

0 comments on commit edc8e82

Please sign in to comment.