Skip to content

Commit

Permalink
check refinements
Browse files Browse the repository at this point in the history
  • Loading branch information
jbardin committed Dec 2, 2024
1 parent 144fdb5 commit 7bda92a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions hclsyntax/expression_ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
},
Expand Down
11 changes: 9 additions & 2 deletions hclsyntax/expression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1939,7 +1939,7 @@ EOT
"list": cty.ListValEmpty(cty.Bool),
},
},
cty.UnknownVal(cty.Bool),
cty.UnknownVal(cty.Bool).RefineNotNull(),
0,
},
{
Expand Down Expand Up @@ -1968,7 +1968,7 @@ EOT
"list": cty.ListValEmpty(cty.Bool),
},
},
cty.UnknownVal(cty.Bool),
cty.UnknownVal(cty.Bool).RefineNotNull(),
0,
},
{
Expand Down Expand Up @@ -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),
Expand All @@ -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
}
Expand Down

0 comments on commit 7bda92a

Please sign in to comment.