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

Fix WithScope for destructured post arguments #396

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
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
4 changes: 2 additions & 2 deletions lib/syntax_tree/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8277,8 +8277,8 @@ def format(q)
# parameter
attr_reader :rest

# [Array[ Ident ]] any positional parameters that exist after a rest
# parameter
# [Array[ Ident | MLHSParen ]] any positional parameters that exist after a
# rest parameter
attr_reader :posts

# [Array[ [ Label, nil | Node ] ]] any keyword parameters and their
Expand Down
5 changes: 1 addition & 4 deletions lib/syntax_tree/with_scope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,7 @@ def visit_def(node)
# arguments.
def visit_params(node)
add_argument_definitions(node.requireds)

node.posts.each do |param|
current_scope.add_local_definition(param, :argument)
end
add_argument_definitions(node.posts)

node.keywords.each do |param|
current_scope.add_local_definition(param.first, :argument)
Expand Down
36 changes: 36 additions & 0 deletions test/with_scope_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,42 @@ def foo(a)
assert_argument(collector, "a", definitions: [1], usages: [2])
end

def test_collecting_methods_with_destructured_post_arguments
collector = Collector.collect(<<~RUBY)
def foo(optional = 1, (bin, bag))
end
RUBY

assert_equal(3, collector.arguments.length)
assert_argument(collector, "optional", definitions: [1], usages: [])
assert_argument(collector, "bin", definitions: [1], usages: [])
assert_argument(collector, "bag", definitions: [1], usages: [])
end

def test_collecting_methods_with_desctructured_post_using_splat
collector = Collector.collect(<<~RUBY)
def foo(optional = 1, (bin, bag, *))
end
RUBY

assert_equal(3, collector.arguments.length)
assert_argument(collector, "optional", definitions: [1], usages: [])
assert_argument(collector, "bin", definitions: [1], usages: [])
assert_argument(collector, "bag", definitions: [1], usages: [])
end

def test_collecting_methods_with_nested_desctructured
collector = Collector.collect(<<~RUBY)
def foo(optional = 1, (bin, (bag)))
end
RUBY

assert_equal(3, collector.arguments.length)
assert_argument(collector, "optional", definitions: [1], usages: [])
assert_argument(collector, "bin", definitions: [1], usages: [])
assert_argument(collector, "bag", definitions: [1], usages: [])
end

def test_collecting_singleton_method_arguments
collector = Collector.collect(<<~RUBY)
def self.foo(a)
Expand Down