zclsyntax: convert condition expr to bool in ConditionalExpr

This commit is contained in:
Martin Atkins 2017-05-31 19:30:17 -07:00
parent 085dff2472
commit 8f26a22933

View File

@ -298,6 +298,17 @@ func (e *ConditionalExpr) Value(ctx *zcl.EvalContext) (cty.Value, zcl.Diagnostic
if !condResult.IsKnown() {
return cty.UnknownVal(resultType), diags
}
condResult, err := convert.Convert(condResult, cty.Bool)
if err != nil {
diags = append(diags, &zcl.Diagnostic{
Severity: zcl.DiagError,
Summary: "Incorrect condition type",
Detail: fmt.Sprintf("The condition expression must be of type bool."),
Subject: e.Condition.Range().Ptr(),
Context: &e.SrcRange,
})
return cty.UnknownVal(resultType), diags
}
if condResult.True() {
diags = append(diags, trueDiags...)