status-im / nim-stew

stew is collection of utilities, std library extensions and budding libraries that are frequently used at Status, but are too small to deserve their own git repository.
139 stars 18 forks source link

results.Opt as object fields could generate codegen issues #142

Closed cheatfate closed 1 year ago

cheatfate commented 2 years ago

All Nim versions are affected https://github.com/status-im/nim-stew/pull/141

import stew/results

type
  ValidatorSig = object
    blob: array[96, byte]
  SyncDutyAndProof = object
    slotSig: Opt[ValidatorSig]
const
  DefaultSyncDutyAndProof =
    SyncDutyAndProof(slotSig: Opt.none(ValidatorSig))

echo DefaultSyncDutyAndProof
/home/runner/.cache/nim/all_tests_d/@mtest_results.nim.c:974:143: error: ‘union <anonymous>’ has no member named ‘_o_1’; did you mean ‘_o_2’?
 N_LIB_PRIVATE NIM_CONST tyObject_SyncDutyAndProof__9atwCZvu9aDnhulGNwFXJ9cFg DefaultSyncDutyAndProof__qmlenLhfD5mHF063hF585Q = {{NIM_FALSE, {._o_1 = {}}}
                                                                                                                                               ^~~~
                                                                                                                                               _o_2
deech commented 1 year ago

Seems like a bug in Nim itself

deech commented 1 year ago

https://github.com/nim-lang/Nim/pull/20790 should fix it.

arnetheduck commented 1 year ago

This is fixed both by #150 and upstream fixes