Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

function/stdlib: Fix panic with unknown set values #59

Merged
merged 1 commit into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
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