Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 77bdc12

Browse files
vinistockkddnewton
andcommitted
Fix WithScope visits for deconstructed block params
Co-authored-by: Kevin Newton <kddnewton@users.noreply.github.com>
1 parent 654ebcb commit 77bdc12

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/syntax_tree/with_scope.rb

Lines changed: 5 additions & 1 deletion
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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,25 @@ 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+
201220
def test_collecting_one_line_block_arguments
202221
collector = Collector.collect(<<~RUBY)
203222
def foo

0 commit comments

Comments
 (0)