Actions
Bug #22183
closedparse.y interpolation inside lambda literal
Bug #22183:
parse.y interpolation inside lambda literal
Description
This is an odd bug that I think is just leaking parse.y internals to do with paren_nest and lambda_beginning_p.
In parse.y, p->lex.lpar_beg is not isolated when the lexer enters a string interpolation (tSTRING_DBEG). So lambda_beginning_p() can be true inside an interpolation that appears between a lambda's -> and its body, causing a do or { inside the interpolation to be lexed as keyword_do_LAMBDA / tLAMBEG and produce a syntax error.
$ ruby --parser=parse.y -c test.rb
test.rb: test.rb:1: syntax error found (SyntaxError)
> 1 | -> a = "#{foo do end}" do end
| ^~ unexpected 'do' for lambda, ...
The same applies with a brace block inside the interpolation:
I'm not 100% sure about this one to be honest. I guess it could potentially have been a design decision? But it seems inconsistent:
Actions