diff --git a/cty/function/stdlib/set.go b/cty/function/stdlib/set.go index ce1a52ee..37eab999 100644 --- a/cty/function/stdlib/set.go +++ b/cty/function/stdlib/set.go @@ -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 } diff --git a/cty/function/stdlib/set_test.go b/cty/function/stdlib/set_test.go index bb593f78..9aec2611 100644 --- a/cty/function/stdlib/set_test.go +++ b/cty/function/stdlib/set_test.go @@ -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 { @@ -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 { @@ -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 {