Open
Description
As the title says, a very specific case involving Options causes Nim to generate invalid C.
Example
import options
type Nested = ref object
child: Option[Nested]
let x = none(Nested)
discard some(Nested()[])
Current Output
~/.cache/nim/test_codegen_d/stdlib_options.nim.c: In function ‘some__9ahAc9c9c9bfjwxun9c9c2ibgAFg’:
~/.cache/nim/test_codegen_d/stdlib_options.nim.c:324:21: error: ‘tyObject_Option__LdGjTDNxAxkpdsbs9c9aMtGQ {aka struct tyObject_Option__LdGjTDNxAxkpdsbs9c9aMtGQ}’ has no member named ‘has’
(*Result).val.child.has = val.child.has;
^
~/.cache/nim/test_codegen_d/stdlib_options.nim.c:324:37: error: ‘tyObject_Option__LdGjTDNxAxkpdsbs9c9aMtGQ {aka struct tyObject_Option__LdGjTDNxAxkpdsbs9c9aMtGQ}’ has no member named ‘has’
(*Result).val.child.has = val.child.has;
^
Error: execution of an external compiler program 'gcc -c -w -pthread -I'~/.choosenim/toolchains/nim-#devel/lib' -o ~/.cache/nim/test_codegen_d/stdlib_options.nim.c.o ~/.cache/nim/test_codegen_d/stdlib_options.nim.c' failed with exit code: 1
Expected Output
A runtime error that you can't get a value from None.
Additional Information
- Inlining any of this causes valid code to be generated.
- Using a non-circular type also causes valid code to be generated.
- Using some instead of none also causes valid code to be generated.
Tested on 1.2.0 and the latest devel.