Let's say I have this type of _ref object_ :
type
ValueKind = enum
Integer
String
Block
Value = ref object
case kind: ValueKind:
of Integer:
i: int
of String:
s: string
of Block:
a: seq[Value]
Run
To normally create new Value's, we can do something like this:
var v1 = Value(kind: Integer, i: 2)
var v2 = Value(kind: String, s: "hello world")
# now, let's say we want to re-assign one of our Value's...
v2 = Value(kind: Integer, i: 3)
Run
And everything's fine.
The question is: what if I change a previously-set Value, internally - by
changing its fields?
Based on the above example:
var v2 = Value(kind: String, s: "hello world")
# now, let's say we want to re-assign one of our Value's...
v2.kind = Integer
v2.i = 3
Run
Apparently, this is not only valid code but also working.
Is there any catch I'm missing here?