Skip to content

Fix WithScope visits for deconstructed block params #328

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

Merged
Merged
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
6 changes: 5 additions & 1 deletion lib/syntax_tree/with_scope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,11 @@ def visit_var_ref(node)

def add_argument_definitions(list)
list.each do |param|
if param.is_a?(SyntaxTree::MLHSParen)
case param
when ArgStar
value = param.value
current_scope.add_local_definition(value, :argument) if value
when MLHSParen
add_argument_definitions(param.contents.parts)
else
current_scope.add_local_definition(param, :argument)
Expand Down
19 changes: 19 additions & 0 deletions test/with_scope_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,25 @@ def foo
assert_argument(collector, "i", definitions: [2], usages: [3])
end

def test_collecting_destructured_block_arguments
collector = Collector.collect(<<~RUBY)
[].each do |(a, *b)|
end
RUBY

assert_equal(2, collector.arguments.length)
assert_argument(collector, "b", definitions: [1])
end

def test_collecting_anonymous_destructured_block_arguments
collector = Collector.collect(<<~RUBY)
[].each do |(a, *)|
end
RUBY

assert_equal(1, collector.arguments.length)
end

def test_collecting_one_line_block_arguments
collector = Collector.collect(<<~RUBY)
def foo
Expand Down