@@ -42,11 +42,13 @@ type ValueCreator interface {
4242// The recommended usage of a Value is to check that it is known, using
4343// Value.IsKnown, then to convert it to a Go type, using Value.As. The Go type
4444// can then be manipulated.
45+ //
46+ // TODO: add docs for new refinement data
4547type Value struct {
4648 typ Type
4749 value interface {}
4850
49- refinements refinement.Refinements //nolint
51+ refinements refinement.Refinements
5052}
5153
5254func (val Value ) String () string {
@@ -62,6 +64,7 @@ func (val Value) String() string {
6264 }
6365
6466 // TODO: print refinements
67+
6568 if ! val .IsKnown () {
6669 return typ .String () + "<unknown>"
6770 }
@@ -226,7 +229,9 @@ func (val Value) Equal(o Value) bool {
226229 if ! val .Type ().Equal (o .Type ()) {
227230 return false
228231 }
232+
229233 // TODO: compare refinements
234+
230235 deepEqual , err := val .deepEqual (o )
231236 if err != nil {
232237 return false
@@ -237,6 +242,9 @@ func (val Value) Equal(o Value) bool {
237242// Copy returns a defensively-copied clone of Value that shares no underlying
238243// data structures with the original Value and can be mutated without
239244// accidentally mutating the original.
245+ //
246+ // TODO: Make sure this actually works for refinements. Consuming packages should not be able to mutate refinements of val
247+ // TODO: Add docs referencing refinements
240248func (val Value ) Copy () Value {
241249 newVal := val .value
242250 switch v := val .value .(type ) {
@@ -253,7 +261,11 @@ func (val Value) Copy() Value {
253261 }
254262 newVal = newVals
255263 }
256- return NewValue (val .Type (), newVal )
264+
265+ newTfValue := NewValue (val .Type (), newVal )
266+ newTfValue .refinements = val .refinements
267+
268+ return newTfValue
257269}
258270
259271// NewValue returns a Value constructed using the specified Type and stores the
@@ -599,7 +611,7 @@ func unexpectedValueTypeError(p *AttributePath, expected, got interface{}, typ T
599611 return p .NewErrorf ("unexpected value type %T, %s values must be of type %T" , got , typ , expected )
600612}
601613
602- // TODO: return error?
614+ // TODO: do we need to return an error? Like if you attempt to refine a value improperly (like string prefix on a number) ?
603615func (val Value ) Refine (refinements refinement.Refinements ) Value {
604616 newVal := val .Copy ()
605617
@@ -611,6 +623,8 @@ func (val Value) Refine(refinements refinement.Refinements) Value {
611623}
612624
613625func (val Value ) Refinements () refinement.Refinements {
626+ // TODO: is this copy really needed?
614627 valCopy := val .Copy ()
628+
615629 return valCopy .refinements
616630}
0 commit comments