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.
135 stars 18 forks source link

results.Opt in constants could generate codegen issues. #149

Closed cheatfate closed 1 year ago

cheatfate commented 1 year ago

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
arnetheduck commented 1 year ago

fixed in #150