Skip to content

Commit

Permalink
cty: Explicit panic when using Value.Range with marked value
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
apparentlymart committed Oct 5, 2023
1 parent 3071166 commit ab81272
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cty/value_range.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ab81272

Please sign in to comment.