Please help me fix this code:
@parameter
if False:
comptime s = "Hello"
else:
comptime s = "World"
fn main():
print(s)
Error:
error: use of unknown declaration 's'
print(s)
^
Please help me fix this code:
@parameter
if False:
comptime s = "Hello"
else:
comptime s = "World"
fn main():
print(s)
Error:
error: use of unknown declaration 's'
print(s)
^
Interestingly, the following works on current nightly:
comptime s = "Hello" if False else "World"
fn main():
print(s)
ASM generation compiler returned: 0
Execution build compiler returned: 0
Program returned: 0
World
Yea, that’s roughly control flow vs just a expression.
The “if else” approach is the right approach. @parameter if isn’t like a #ifdef in that removed by a preprocessor. It has proper scoping.