when statements branches exit early (#17143)
When statement branches exit early outside of nimvm. In nimvm it seems that all sides of the branches must be evaluated as the code gen happens at a later stage, this remains intact.
This commit is contained in:
parent
05711d95e0
commit
2aba116bbc
3 changed files with 72 additions and 0 deletions
24
tests/whenstmt/twhen_macro.nim
Normal file
24
tests/whenstmt/twhen_macro.nim
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import macros
|
||||
|
||||
discard """
|
||||
output: '''
|
||||
when - test
|
||||
'''
|
||||
"""
|
||||
|
||||
# test that when stmt works from within a macro
|
||||
|
||||
macro output(s: string, xs: varargs[untyped]): auto =
|
||||
result = quote do:
|
||||
when compiles(`s`):
|
||||
"when - " & `s`
|
||||
elif compiles(`s`):
|
||||
"elif - " & `s`
|
||||
# should never get here so this should not break
|
||||
broken.xs
|
||||
else:
|
||||
"else - " & `s`
|
||||
# should never get here so this should not break
|
||||
more.broken.xs
|
||||
|
||||
echo output("test")
|
||||
Loading…
Add table
Add a link
Reference in a new issue