I think there's a bug but I want to make sure there's not something I'm missing.
Consider this code:
# foo.nim
import std/options
type
Foo* = ref object of RootObj
parent*: Option[Foo]
func newFoo*(parent = none Foo): Foo =
Foo(parent: parent)
when isMainModule:
let f = newFoo()
echo f[]
This code works just fine:
$ nim r foo.nim
...
(parent: ...)
However, when I move the type declaration to another module, things go South with a weird error message:
# foo.nim
import bar
when isMainModule:
let f = newFoo()
echo f[]
# bar.nim
import std/options
type
Foo* = ref object of RootObj
parent*: Option[Foo]
func newFoo*(parent = none Foo): Foo =
Foo(parent: parent)
$ nim r foo.nim
Hint: used config file 'C:\Users\moigagoo\.choosenim\toolchains\nim-1.6.2\config\nim.cfg' [Conf]
Hint: used config file 'C:\Users\moigagoo\.choosenim\toolchains\nim-1.6.2\config\config.nims' [Conf]
..............................................................
CC: stdlib_system.nim
CC: bar.nim
CC: foo.nim
C:\Users\moigagoo\nimcache\foo_d\@mfoo.nim.c: In function 'dollar___foo_126':
C:\Users\moigagoo\nimcache\foo_d\@mfoo.nim.c:446:40: error: 'tyObject_Option__csSRI9cOcewCdf39c1CwKH0Q' has no member named 'has'
446 | addQuoted__foo_150((&result), x.has);
| ^
Error: execution of an external compiler program 'gcc.exe -c -w -fmax-errors=3 -mno-ms-bitfields -IC:\Users\moigagoo\.choosenim\toolchains\nim-1.6.2\lib -IC:\Users\moigagoo\Projects -o C:\Users\moigagoo\nimcache\foo_d\@mfoo.nim.c.o C:\Users\moigagoo\nimcache\foo_d\@mfoo.nim.c' failed with exit code: 1
Is this intended? How to I fix that?
Thanks! I'll report my case.
Unfortunatey, I can't use the proposed fix. I'm describing a Norm model and each object field corresponds to a DB column, so I can't just add fields.