Skip to content

Commit 3f7d4bc

Browse files
committed
[Bug #22183] Preserve lpar_beg across interpolation
Fix unexpected `keyword_do_LAMBDA` inside string interpolation within default argument of lambda.
1 parent 23f0283 commit 3f7d4bc

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

parse.y

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6062,6 +6062,10 @@ string_content : tSTRING_CONTENT[content]
60626062
$$ = p->lex.brace_nest;
60636063
p->lex.brace_nest = 0;
60646064
}[brace]<num>
6065+
{
6066+
$$ = p->lex.lpar_beg;
6067+
p->lex.lpar_beg = -1;
6068+
}[lpar]<num>
60656069
{
60666070
$$ = p->heredoc_indent;
60676071
p->heredoc_indent = 0;
@@ -6073,6 +6077,7 @@ string_content : tSTRING_CONTENT[content]
60736077
p->lex.strterm = $term;
60746078
SET_LEX_STATE($state);
60756079
p->lex.brace_nest = $brace;
6080+
p->lex.lpar_beg = $lpar;
60766081
p->heredoc_indent = $indent;
60776082
p->heredoc_line_indent = -1;
60786083
if ($compstmt) nd_unset_fl_newline($compstmt);

test/ruby/test_parse.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,12 @@ def test_do_lambda
323323
end
324324
a.call
325325
assert_equal(42, b)
326+
327+
obj = BasicObject.new
328+
assert_nothing_raised do
329+
a = obj.instance_eval('-> a = "#{foo do end}" do end', __FILE__, __LINE__)
330+
end
331+
assert_raise_with_message(NoMethodError, /foo/) {a.call}
326332
end
327333

328334
def test_block_call_colon2

0 commit comments

Comments
 (0)