Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# 1.5.1 (Unreleased)

* `function/stdlib`: The `merge` function will no longer panic if all given maps are empty. ([#58](https://github.com/zclconf/go-cty/pull/58))
* `function/stdlib`: The various set-manipulation functions, like `setunion`, will no longer panic if given an unknown set value. ([#59](https://github.com/zclconf/go-cty/pull/59))

# 1.5.0 (March 17, 2025)

* `cty`: New `Value.HasWhollyKnownType` method, for testing whether a value's type could potentially change if any unknown values it was constructed from were to become known. ([#55](https://github.com/zclconf/go-cty/pull/55))
* `convert`: Fix incorrect panic when converting a tuple with a dynamic-typed null member into a list or set, due to overly-liberal type unification. ([#56](https://github.com/zclconf/go-cty/pull/56))

# 1.4.2 (Unreleased)
# 1.4.2

* `function/stdlib`: The `jsonencode` function will now correctly accept a null as its argument, and produce the JSON representation `"null"` rather than returning an error. ([#54](https://github.com/zclconf/go-cty/pull/54))
* `convert`: Don't panic when asked to convert a tuple of objects to a list type constraint containing a nested `cty.DynamicPseudoType`. ([#53](https://github.com/zclconf/go-cty/pull/53))
Expand Down
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
2 changes: 1 addition & 1 deletion cty/function/stdlib/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func setOperationReturnType(args []cty.Value) (ret cty.Type, err error) {

// Do not unify types for empty dynamic pseudo typed collections. These
// will always convert to any other concrete type.
if arg.LengthInt() == 0 && ty.Equals(cty.DynamicPseudoType) {
if arg.IsKnown() && arg.LengthInt() == 0 && ty.Equals(cty.DynamicPseudoType) {
continue
}

Expand Down
19 changes: 19 additions & 0 deletions cty/function/stdlib/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ func TestSetUnion(t *testing.T) {
},
cty.SetValEmpty(cty.DynamicPseudoType),
},
{
[]cty.Value{
cty.SetVal([]cty.Value{cty.StringVal("5")}),
cty.UnknownVal(cty.Set(cty.Number)),
},
cty.UnknownVal(cty.Set(cty.String)),
},
}

for _, test := range tests {
Expand Down Expand Up @@ -159,6 +166,13 @@ func TestSetIntersection(t *testing.T) {
},
cty.SetValEmpty(cty.DynamicPseudoType),
},
{
[]cty.Value{
cty.SetVal([]cty.Value{cty.StringVal("5")}),
cty.UnknownVal(cty.Set(cty.Number)),
},
cty.UnknownVal(cty.Set(cty.String)),
},
}

for _, test := range tests {
Expand Down Expand Up @@ -226,6 +240,11 @@ func TestSetSubtract(t *testing.T) {
cty.SetValEmpty(cty.DynamicPseudoType),
cty.SetValEmpty(cty.DynamicPseudoType),
},
{
cty.SetVal([]cty.Value{cty.StringVal("5")}),
cty.UnknownVal(cty.Set(cty.Number)),
cty.UnknownVal(cty.Set(cty.String)),
},
}

for _, test := range tests {
Expand Down