Skip to content

Commit 7c8870d

Browse files
vinistockkddnewton
andcommitted
Fix WithScope visits for deconstructed block params
Co-authored-by: Kevin Newton <[email protected]>
1 parent 654ebcb commit 7c8870d

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

lib/syntax_tree/with_scope.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,11 @@ def visit_var_ref(node)
221221

222222
def add_argument_definitions(list)
223223
list.each do |param|
224-
if param.is_a?(SyntaxTree::MLHSParen)
224+
case param
225+
when ArgStar
226+
value = param.value
227+
current_scope.add_local_definition(value, :argument) if value
228+
when MLHSParen
225229
add_argument_definitions(param.contents.parts)
226230
else
227231
current_scope.add_local_definition(param, :argument)

test/with_scope_test.rb

+28
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,34 @@ def foo
198198
assert_argument(collector, "i", definitions: [2], usages: [3])
199199
end
200200

201+
def test_collecting_destructured_block_arguments
202+
collector = Collector.collect(<<~RUBY)
203+
[].each do |(a, *b)|
204+
end
205+
RUBY
206+
207+
assert_equal(2, collector.arguments.length)
208+
assert_argument(collector, "b", definitions: [1])
209+
end
210+
211+
def test_collecting_anonymous_destructured_block_arguments
212+
collector = Collector.collect(<<~RUBY)
213+
[].each do |(a, *)|
214+
end
215+
RUBY
216+
217+
assert_equal(1, collector.arguments.length)
218+
end
219+
220+
def test_collecting_testtest
221+
collector = Collector.collect(<<~RUBY)
222+
[].each do |(a, **args)|
223+
end
224+
RUBY
225+
226+
assert_equal(1, collector.arguments.length)
227+
end
228+
201229
def test_collecting_one_line_block_arguments
202230
collector = Collector.collect(<<~RUBY)
203231
def foo

0 commit comments

Comments
 (0)