diff --git a/hclsyntax/expression_ops.go b/hclsyntax/expression_ops.go index 23b307d8..4e537d72 100644 --- a/hclsyntax/expression_ops.go +++ b/hclsyntax/expression_ops.go @@ -41,7 +41,7 @@ var ( if rhs.IsKnown() && rhs.True() { return cty.True } - return cty.UnknownVal(cty.Bool) + return cty.UnknownVal(cty.Bool).RefineNotNull() } return cty.NilVal @@ -60,7 +60,7 @@ var ( if rhs.IsKnown() && rhs.False() { return cty.False } - return cty.UnknownVal(cty.Bool) + return cty.UnknownVal(cty.Bool).RefineNotNull() } return cty.NilVal }, diff --git a/hclsyntax/expression_test.go b/hclsyntax/expression_test.go index 376073ad..d1dc35b9 100644 --- a/hclsyntax/expression_test.go +++ b/hclsyntax/expression_test.go @@ -1939,7 +1939,7 @@ EOT "list": cty.ListValEmpty(cty.Bool), }, }, - cty.UnknownVal(cty.Bool), + cty.UnknownVal(cty.Bool).RefineNotNull(), 0, }, { @@ -1968,7 +1968,7 @@ EOT "list": cty.ListValEmpty(cty.Bool), }, }, - cty.UnknownVal(cty.Bool), + cty.UnknownVal(cty.Bool).RefineNotNull(), 0, }, { @@ -3059,6 +3059,9 @@ func TestAllBoolExpressions(t *testing.T) { for input, want := range inputs { t.Run(input, func(t *testing.T) { + if !want.IsKnown() { + want = cty.UnknownVal(cty.Bool).RefineNotNull() + } ctx := &hcl.EvalContext{ Variables: map[string]cty.Value{ "unknown": cty.UnknownVal(cty.DynamicPseudoType), @@ -3077,6 +3080,10 @@ func TestAllBoolExpressions(t *testing.T) { t.Fatalf("%q resulted in %#v, wanted %#v\n", input, got, want) } if !got.IsKnown() { + // this validates that the uknown refinements are correct too + if !got.RawEquals(want) { + t.Fatalf("wrong unknown, got:%#v, want:%#v\n", got, want) + } // covered in known comparison return }