status-im/nim-stew

results.Opt in constants could generate codegen issues.

Closed this issue · 1 comments

At least Nim 1.6 is affected but i suspect all versions are affected.

Nim Compiler Version 1.6.9 [Windows: amd64]
Compiled at 2022-10-17
Copyright (c) 2006-2021 by Andreas Rumpf

git hash: 8b86ba96f848500154a24f4f9acb7f0774023a09
active boot switches: -d:release
import stew/results

type
  Epoch* = distinct uint64

const
  TestVectors = [
    ("", Opt.some(Epoch(3))),
    ("", Opt.none(Epoch))
  ]

for item in TestVectors:
  if item[1].isSome():
    echo uint64(item[1].get())
  else:
    echo "<none>"

Produces

nimcache\test_stew2_d\@mtest_stew2.nim.c:233:15: error: 'union <anonymous>' has no member named '_o_1'; did you mean '_o_2'?
  233 | {NIM_FALSE, {._o_1 = {}}}
      |               ^~~~
      |               _o_2

fixed in #150