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

Commit 1510e4f

Browse files
authored
Merge pull request #328 from vinistock/vs/fix_deconstructed_block_params
Fix WithScope visits for deconstructed block params
2 parents 384a0d2 + 77bdc12 commit 1510e4f

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
@@ -287,7 +287,11 @@ def visit_binary(node)
287287

288288
def add_argument_definitions(list)
289289
list.each do |param|
290-
if param.is_a?(SyntaxTree::MLHSParen)
290+
case param
291+
when ArgStar
292+
value = param.value
293+
current_scope.add_local_definition(value, :argument) if value
294+
when MLHSParen
291295
add_argument_definitions(param.contents.parts)
292296
else
293297
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
@@ -201,6 +201,25 @@ def foo
201201
assert_argument(collector, "i", definitions: [2], usages: [3])
202202
end
203203

204+
def test_collecting_destructured_block_arguments
205+
collector = Collector.collect(<<~RUBY)
206+
[].each do |(a, *b)|
207+
end
208+
RUBY
209+
210+
assert_equal(2, collector.arguments.length)
211+
assert_argument(collector, "b", definitions: [1])
212+
end
213+
214+
def test_collecting_anonymous_destructured_block_arguments
215+
collector = Collector.collect(<<~RUBY)
216+
[].each do |(a, *)|
217+
end
218+
RUBY
219+
220+
assert_equal(1, collector.arguments.length)
221+
end
222+
204223
def test_collecting_one_line_block_arguments
205224
collector = Collector.collect(<<~RUBY)
206225
def foo

0 commit comments

Comments
 (0)