Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- builder.rb: correctly handle ... forwarding to super with explicit block #1049

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions lib/parser/builders/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1120,15 +1120,19 @@ def call_lambda(lambda_t)
end

def block(method_call, begin_t, args, body, end_t)
_receiver, _selector, *call_args = *method_call

if method_call.type == :yield
diagnostic :error, :block_given_to_yield, nil, method_call.loc.keyword, [loc(begin_t)]
end

last_arg = call_args.last
if method_call.type == :super
*_args, last_arg = *method_call
else
_receiver, _selector, *_args, last_arg = *method_call
end
if last_arg && (last_arg.type == :block_pass || last_arg.type == :forwarded_args)
diagnostic :error, :block_and_blockarg, nil, last_arg.loc.expression, [loc(begin_t)]
if (@parser.version == 33 && method_call.type != :super) || @parser.version != 33
iliabylich marked this conversation as resolved.
Show resolved Hide resolved
diagnostic :error, :block_and_blockarg, nil, last_arg.loc.expression, [loc(begin_t)]
end
end

if args.type == :numargs
Expand Down
24 changes: 24 additions & 0 deletions test/test_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8163,6 +8163,30 @@ def test_forward_args_invalid
SINCE_3_1 - SINCE_2_7)
end

def test_forward_args_super_with_block
[
%q{def foo(...) super(...) {}; end},
%q{def foo(...) super(a, ...) {}; end},
%q{def foo(...) super(a, b, ...) {}; end},
].each do |code|
# https://bugs.ruby-lang.org/issues/20392
refute_diagnoses(code, %w(3.3))
assert_diagnoses(
[:error, :block_and_blockarg],
code,
%q{},
SINCE_2_7 - %w(3.3))
end

[
%q{def foo(...) super {}; end},
%q{def foo(...) super() {}; end},
%q{def foo(...) super(a) {}; end},
%q{def foo(...) super(a, b) {}; end},
].each do |code|
refute_diagnoses(code, SINCE_2_7)
end
end
def test_trailing_forward_arg
assert_parses(
s(:def, :foo,
Expand Down
Loading