You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Invalid C code generated when creating an Option out of deref'd value, which contains a reference to its own type, gotten from an Option which is None at compile time.
#14387
Open
kayabaNerve opened this issue
May 18, 2020
· 3 comments
As the title says, a very specific case involving Options causes Nim to generate invalid C.
Example
import options
typeNested=refobject
child: Option[Nested]
let x =none(Nested)
discardsome(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.
The text was updated successfully, but these errors were encountered:
kayabaNerve
changed the title
Invalid C code generated when creating an Option out of deref'd value gotten from an Option which is None at compile time.
Invalid C code generated when creating an Option out of deref'd value, which contains a reference to its own type, gotten from an Option which is None at compile time.
May 18, 2020
related to #12695
when reducing that bug, which also involves a nested type:
typeFoo[T] =objectwhen T isptr:
value:T
else:
notvalue:T
procaccess[A](self:A) =discardprocstore[T](self: varFoo[ptr T]) =access(self.value)
typeMyType=ptrobject
next: Foo[MyType]
var f:Foo[MyType]
f.store()
i get
CC: bug1.nim
/home/bwsq/.cache/nim/bug1_d/@mbug1.nim.c: In function ‘store__bug49_29’:
/home/bwsq/.cache/nim/bug1_d/@mbug1.nim.c:82:34: error: ‘tyObject_Foo__D9a9
crXqyX59c9a5NYkXwC5XKw’ has no member named ‘value’; did you mean ‘notvalue
’?
82 | access__bug49_35((*self).value);
| ^~~~~
| notvalue
As the title says, a very specific case involving Options causes Nim to generate invalid C.
Example
Current Output
Expected Output
A runtime error that you can't get a value from None.
Additional Information
Tested on 1.2.0 and the latest devel.
The text was updated successfully, but these errors were encountered: