I've encountered something weird. Not sure if it is a bug or if I'm missing something.
Works:
if not init():
quit(1)
else:
ok()
Does not work:
if init():
ok()
else:
quit(1)
Telling me:
Error: expression 'quit(1)' is of type 'bool' and has to be used (or discarded);
Even though,
quit never returns
as stated here.
I looked into it a bit further.
Your ok function returns bool and is {.discardable.} correct?
The type of an if stmt is determined by it's first branch.
If the first branch is quit(1) the type is void and ok() {.discardable.} is compatible.
However if the first branch is ok() it determines the type to be bool which is a little strange because if you replaced
quit(1)
with
echo "quit"
the type would be void and the program would work.
So this may be a bug with how quit() interacts with discardable.
You can work around it with
if init():
discard ok()
else:
quit(1)
or
if init():
ok()
else:
quit(1)
discard
Your ok function returns bool and is {.discardable.} correct?
The type of an if stmt is determined by it's first branch.
Wow. You are precisely correct. I did not know about the type thing for an if statement.
So this may be a bug with how quit() interacts with discardable.
Although, this is nonetheless a slight bug, after all?
Anyway, thanks for your help! I'm learning every single day... :)