Skip to content

Commit

Permalink
Fix error of conditionals with an unknown condition and marked branch.
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Martin <kubam@spacelift.io>
  • Loading branch information
cube2222 authored and apparentlymart committed Oct 6, 2023
1 parent 073c386 commit 5b881c6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion hclsyntax/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -742,13 +742,17 @@ func (e *ConditionalExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostic
}
}
}
_, condResultMarks := condResult.Unmark()
trueResult, trueResultMarks := trueResult.Unmark()
falseResult, falseResultMarks := falseResult.Unmark()

trueRng := trueResult.Range()
falseRng := falseResult.Range()
ret := cty.UnknownVal(resultType)
if trueRng.DefinitelyNotNull() && falseRng.DefinitelyNotNull() {
ret = ret.RefineNotNull()
}
return ret.WithSameMarks(condResult).WithSameMarks(trueResult).WithSameMarks(falseResult), diags
return ret.WithMarks(condResultMarks, trueResultMarks, falseResultMarks), diags
}
condResult, err := convert.Convert(condResult, cty.Bool)
if err != nil {
Expand Down
12 changes: 12 additions & 0 deletions hclsyntax/expression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2015,6 +2015,18 @@ EOT
cty.NumberIntVal(1).Mark("sensitive"),
0,
},
{
`test ? sensitiveString : ""`,
&hcl.EvalContext{
Functions: map[string]function.Function{},
Variables: map[string]cty.Value{
"test": cty.UnknownVal(cty.Bool),
"sensitiveString": cty.StringVal("test").Mark("sensitive"),
},
},
cty.UnknownVal(cty.String).RefineNotNull().Mark("sensitive"),
0,
},
}

for _, test := range tests {
Expand Down

0 comments on commit 5b881c6

Please sign in to comment.