Skip to content

Commit c5b51bd

Browse files
committed
[Bug #21712] Allow .() call for command with block
This commit allows codes like `a b do end.()` and `a b do end&.()`.
1 parent 278a93a commit c5b51bd

3 files changed

Lines changed: 28 additions & 0 deletions

File tree

parse.y

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5235,6 +5235,12 @@ block_call : command do_block
52355235
$$ = new_command_qcall(p, $2, $1, $3, $4, $5, &@3, &@$);
52365236
/*% ripper: method_add_block!(command_call!($:1, $:2, $:3, $:4), $:5) %*/
52375237
}
5238+
| block_call call_op2 paren_args
5239+
{
5240+
$$ = new_qcall(p, $2, $1, idCall, $3, &@2, &@$);
5241+
nd_set_line($$, @2.end_pos.lineno);
5242+
/*% ripper: method_add_arg!(call!($:1, $:2, ID2VAL(idCall)), $:3) %*/
5243+
}
52385244
;
52395245

52405246
method_call : fcall paren_args

test/ripper/test_parser_events.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,13 @@ def test_call
480480
assert_equal true, thru_call
481481
assert_equal "[call(vcall(foo),.,call,[])]", tree
482482

483+
thru_call = false
484+
assert_nothing_raised {
485+
tree = parse("a b do end.()", :on_call) {thru_call = true}
486+
}
487+
assert_equal true, thru_call
488+
assert_equal "[call(command(a,[vcall(b)],&do_block(,bodystmt([void()]))),.,call,[])]", tree
489+
483490
thru_call = false
484491
assert_nothing_raised {
485492
tree = parse("self::foo", :on_call) {thru_call = true}

test/ruby/test_parse.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,21 @@ def test_call_method
352352
assert_equal("foobar", b)
353353
end
354354

355+
def test_call_command
356+
a = b = nil
357+
o = Object.new
358+
def o.m(*arg); proc {|a| arg.join + a }; end
359+
360+
assert_nothing_raised do
361+
o.instance_eval <<-END, __FILE__, __LINE__+1
362+
a = o.m "foo", "bar" do end.("buz")
363+
b = o.m "foo", "bar" do end::("buz")
364+
END
365+
end
366+
assert_equal("foobarbuz", a)
367+
assert_equal("foobarbuz", b)
368+
end
369+
355370
def test_xstring
356371
assert_raise(Errno::ENOENT) do
357372
eval("``")

0 commit comments

Comments
 (0)