[ruby-core:125939] [Ruby Bug#22183] parse.y interpolation inside lambda literal
Issue #22183 has been reported by kddnewton (Kevin Newton). ---------------------------------------- Bug #22183: parse.y interpolation inside lambda literal https://bugs.ruby-lang.org/issues/22183 * Author: kddnewton (Kevin Newton) * Status: Open * Backport: 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN ---------------------------------------- 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 -> a = "#{foo do end}" do end ``` ```console $ 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:
```ruby
-> a = "#{foo { }}" do end # parse.y: syntax error at the `{`, lexed as tLAMBEG
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: ```ruby -> a = ("#{foo do end}") do end # parse.y: OK -> a = "#{foo do end}" do end # parse.y: syntax error ``` -- https://bugs.ruby-lang.org/
Issue #22183 has been updated by k0kubun (Takashi Kokubun). ruby_4_0 backport draft PR: https://github.com/ruby/ruby/pull/17761 ---------------------------------------- Bug #22183: parse.y interpolation inside lambda literal https://bugs.ruby-lang.org/issues/22183#change-117981 * Author: kddnewton (Kevin Newton) * Status: Closed * Backport: 3.3: REQUIRED, 3.4: REQUIRED, 4.0: REQUIRED ---------------------------------------- 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 -> a = "#{foo do end}" do end ``` ```console $ 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:
```ruby
-> a = "#{foo { }}" do end # parse.y: syntax error at the `{`, lexed as tLAMBEG
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: ```ruby -> a = ("#{foo do end}") do end # parse.y: OK -> a = "#{foo do end}" do end # parse.y: syntax error ``` -- https://bugs.ruby-lang.org/
Issue #22183 has been updated by k0kubun (Takashi Kokubun). Backport changed from 3.3: REQUIRED, 3.4: REQUIRED, 4.0: REQUIRED to 3.3: REQUIRED, 3.4: REQUIRED, 4.0: DONE ruby_4_0 commit:487b9e94f758a92c350a048eaf4f24f3e7af1002 merged revision(s) commit:3f7d4bc859f03f4c7ea131af910d1c4ae142586d. ---------------------------------------- Bug #22183: parse.y interpolation inside lambda literal https://bugs.ruby-lang.org/issues/22183#change-117989 * Author: kddnewton (Kevin Newton) * Status: Closed * Backport: 3.3: REQUIRED, 3.4: REQUIRED, 4.0: DONE ---------------------------------------- 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 -> a = "#{foo do end}" do end ``` ```console $ 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:
```ruby
-> a = "#{foo { }}" do end # parse.y: syntax error at the `{`, lexed as tLAMBEG
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: ```ruby -> a = ("#{foo do end}") do end # parse.y: OK -> a = "#{foo do end}" do end # parse.y: syntax error ``` -- https://bugs.ruby-lang.org/
participants (2)
-
k0kubun (Takashi Kokubun) -
kddnewton (Kevin Newton)