Log In  

I found some confusing behavior when trying to put multiple if/while shorthands on the same line, e.g.:

if (x1) if(x2) print('true')
print('anyway')

This prints 'anyway' only if x1 is true - whereas I would've expected it to print 'anyway', well - anyway.

It looks like line breaks only terminate a single if/while shorthand, causing the next line to be inside the other shorthand.

It used to be that this code was generating a runtime error, but now it just silently does something really unexpected instead.

P#131999 2023-07-15 08:10

1

It's not that it's bleeding into the next line.

It actually causes the rest of the source code not to run, as if there was an extra or missing "end" or a "return".

I can fill the page below it with fatal code and nothing happens:

if (x1) if(x2) print("true")
print('anyway')
and_now()     
assert()
coresume(nil)

@zep If it's helpful, this variant on @thisismypassword's code produces the following interesting error:

if(x1) if(x2) print("true")
print('anyway')
return

-- syntax error line 3 (tab 0)
-- return
-- unclosed if

This error occurs while still parsing and before execution, indicating that the parser still believes one of the two if blocks isn't ended.

It's kinda weird that it doesn't complain about the block/end imbalance at the end of parsing the original code, without the "return", but instead just runs silently.

P#132030 2023-07-16 12:36 ( Edited 2023-07-16 12:55)

[Please log in to post a comment]