diff --git a/hclsyntax/expression_ops.go b/hclsyntax/expression_ops.go index 2d02c5f6..23b307d8 100644 --- a/hclsyntax/expression_ops.go +++ b/hclsyntax/expression_ops.go @@ -220,8 +220,8 @@ func (e *BinaryOpExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics) return cty.UnknownVal(e.Op.Type), diags } - _, lhsMarks := lhsVal.Unmark() - _, rhsMarks := rhsVal.Unmark() + lhsVal, lhsMarks := lhsVal.Unmark() + rhsVal, rhsMarks := rhsVal.Unmark() // If we short-circuited above and still passed the type-check of RHS then // we'll halt here and return the short-circuit result rather than actually @@ -261,7 +261,7 @@ func (e *BinaryOpExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics) return cty.UnknownVal(e.Op.Type), diags } - return result, diags + return result.WithMarks(lhsMarks, rhsMarks), diags } func (e *BinaryOpExpr) Range() hcl.Range { diff --git a/hclsyntax/expression_test.go b/hclsyntax/expression_test.go index 1a827f86..6768ea86 100644 --- a/hclsyntax/expression_test.go +++ b/hclsyntax/expression_test.go @@ -1971,6 +1971,54 @@ EOT cty.UnknownVal(cty.Bool), 0, }, + { + // short circuit calls must still retain marks + `lhsTrue || rhsUnknown`, + &hcl.EvalContext{ + Variables: map[string]cty.Value{ + "lhsTrue": cty.True.Mark("a"), + "rhsUnknown": cty.UnknownVal(cty.Bool).Mark("b"), + }, + }, + cty.True.Mark("a").Mark("b"), + 0, + }, + { + // short circuit calls must still retain marks + `lhsUnknown || rhsTrue`, + &hcl.EvalContext{ + Variables: map[string]cty.Value{ + "rhsTrue": cty.True.Mark("a"), + "lhsUnknown": cty.UnknownVal(cty.Bool).Mark("b"), + }, + }, + cty.True.Mark("a").Mark("b"), + 0, + }, + { + // short circuit calls must still retain marks + `lhsUnknown && rhsFalse`, + &hcl.EvalContext{ + Variables: map[string]cty.Value{ + "rhsFalse": cty.False.Mark("a"), + "lhsUnknown": cty.UnknownVal(cty.Bool).Mark("b"), + }, + }, + cty.False.Mark("a").Mark("b"), + 0, + }, + { + // short circuit calls must still retain marks + `lhsFalse && rhsUnknown`, + &hcl.EvalContext{ + Variables: map[string]cty.Value{ + "lhsFalse": cty.False.Mark("a"), + "rhsUnknown": cty.UnknownVal(cty.Bool).Mark("b"), + }, + }, + cty.False.Mark("a").Mark("b"), + 0, + }, { `true ? var : null`, &hcl.EvalContext{