From ab81272f70b07f14768ad7a2152a253b165e2688 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Thu, 5 Oct 2023 12:02:03 -0700 Subject: [PATCH] cty: Explicit panic when using Value.Range with marked value As usual with marks, we must panic whenever an operation might cause marks to be silently lost. In such cases, it's always the calling application's responsibility to unmark the value first and then ensure that it applies the appropriate derived marks to whatever new value it's ultimately returning based on the decision. This was already a panic before, but now it's a panic with an explicit message pointing directly at the problem. --- cty/value_range.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cty/value_range.go b/cty/value_range.go index 36f21946..d7d15353 100644 --- a/cty/value_range.go +++ b/cty/value_range.go @@ -21,6 +21,10 @@ import ( // offered by ranges and so can share code between both known and unknown // values. func (v Value) Range() ValueRange { + if v.IsMarked() { + panic("Value.Range on marked value; must be unmarked first") + } + // For an unknown value we just use its own refinements. if unk, isUnk := v.v.(*unknownType); isUnk { refinement := unk.refinement