Actions
Bug #22447
openparse.y `-> do ... end` COND state
Bug #22447:
parse.y `-> do ... end` COND state
Description
With parse.y, do-blocks inside a -> do ... end lambda body are rejected when the lambda appears in a while/until/for condition:
while -> do foo do end end; end
# => syntax error, unexpected 'do' for condition, expecting 'end' or dummy end
The same body is accepted outside a condition, and with brace delimiters inside one:
-> do foo do end end # OK
while -> { foo do end }; end # OK
while (foo do end); end # OK
while def m; foo do end; end; end # OK
while -> do foo do end end; end # SyntaxError
until -> do foo do end end; end # SyntaxError
for x in -> do foo do end end do end # SyntaxError
Nesting a -> do lambda in an unparenthesized lambda parameter default also triggers it:
Pretty much everywhere this kind of thing happens there is a pair of CMDARG_PUSH(0) and COND_PUSH(0), but lambda is missing the latter. I think that's really all that needs to change to make this work:
--- a/parse.y
+++ b/parse.y
@@ lambda : tLAMBDA[lpar]
f_larglist[args]
{
CMDARG_PUSH(0);
+ COND_PUSH(0);
}
lambda_body[body]
{
@@
restore_block_exit(p, $al
+ COND_POP();
CMDARG_POP();
It looks like this was fixed in other places (test_methoddef_in_cond and test_classdef_in_cond both test this kind of thing).
No data to display
Actions