You should be able to do
var myVariant = Object(kind: ...)
let newKind = YourNewKind
copyMem(myVariant.kind.addr, newKind.addr, sizeof(YourKindType))
Run
Thank you! That makes sense.
A related question is how do I initialize the `kind` field in a newly-allocated
memory, without triggering the destroy? I couldn't find a way to set memory
directly.
[Here](https://github.com/gcao/gene/blob/f3ecf762371d91faf58acfb875e1728b9e98ec82/src/gene/types.nim
I think there is no bug here.
`eqdestroy___enum95destroy_u88((&(*t__enum95destroy_u12).kind));` doesn't
destroy the enum field. It's a hacky way the destroy the old object variant (It
uses the address of the start of the object variant)
N_LIB_PRIVATE N_NIMCALL(void,
eqdestroy___te
Here is the issue I opened:
[23189](https://forum.nim-lang.org/postActivity.xml#23189)
Will do. Thanks.
Yes `kind` is an object variant.
Sounds like a codegen bug to me, please report it on github.
Do you have a case in your object on the enum field? i.e. is your object an
[object variant](https://nim-lang.org/docs/manual.html#types-object-variants)?
Why does Nim need to call `=destroy` on an enum field `kind`, when I set a.kind
to SomeEnumValue ? Is there a way to tell the compiler to not call `=destroy`
in this case?
result.kind = kind
Run
{
if (!!(((*result).kind == colontmpD_))) goto LA4_;