Skip to content

Commit 0068978

Browse files
committed
Pinned variables should be treated as usages, not definitions
1 parent 7419218 commit 0068978

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

lib/syntax_tree/with_scope.rb

+7-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,13 @@ def visit_var_field(node)
197197
super
198198
end
199199

200-
alias visit_pinned_var_ref visit_var_field
200+
# Visit for keeping track of local variable definitions
201+
def visit_pinned_var_ref(node)
202+
value = node.value
203+
current_scope.add_local_usage(value, :variable) if value.is_a?(Ident)
204+
205+
super
206+
end
201207

202208
# Visits for keeping track of variable and argument usages
203209
def visit_var_ref(node)

test/with_scope_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def foo
109109
RUBY
110110

111111
assert_equal(2, collector.variables.length)
112-
assert_variable(collector, "a", definitions: [2, 4], usages: [5])
112+
assert_variable(collector, "a", definitions: [2], usages: [4, 5])
113113
assert_variable(collector, "rest", definitions: [4])
114114

115115
# Rest is considered a vcall by the parser instead of a var_ref

0 commit comments

Comments
 (0)