=destroy and enum

2024-01-09 Thread ElegantBeef
You should be able to do var myVariant = Object(kind: ...) let newKind = YourNewKind copyMem(myVariant.kind.addr, newKind.addr, sizeof(YourKindType)) Run

=destroy and enum

2024-01-09 Thread gcao
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

=destroy and enum

2024-01-08 Thread ringabout
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

=destroy and enum

2024-01-08 Thread gcao
Here is the issue I opened: [23189](https://forum.nim-lang.org/postActivity.xml#23189)

=destroy and enum

2024-01-08 Thread gcao
Will do. Thanks.

=destroy and enum

2024-01-08 Thread gcao
Yes `kind` is an object variant.

=destroy and enum

2024-01-08 Thread Araq
Sounds like a codegen bug to me, please report it on github.

=destroy and enum

2024-01-08 Thread mig
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)?

=destroy and enum

2024-01-08 Thread gcao
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_;