Skip to content

Commit bf9768f

Browse files
authored
Merge pull request #770 from Shopify/connieho/index-default-arg-constants
Index constant references in parameter default values
2 parents ca2c87b + d8469bf commit bf9768f

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

rust/rubydex/src/indexing/ruby_indexer.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ impl<'a> RubyIndexer<'a> {
234234
Offset::from_prism_location(&name_loc),
235235
str_id,
236236
)));
237+
self.visit(&opt_param.value());
237238
}
238239

239240
if let Some(rest) = parameters_list.rest() {
@@ -276,6 +277,7 @@ impl<'a> RubyIndexer<'a> {
276277
let str_id = self.local_graph.intern_string(self.offset_to_string(&offset));
277278

278279
parameters.push(Parameter::OptionalKeyword(ParameterStruct::new(offset, str_id)));
280+
self.visit(&optional.value());
279281
}
280282
_ => {}
281283
}

rust/rubydex/src/indexing/ruby_indexer_tests.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4060,6 +4060,19 @@ mod constant_reference_tests {
40604060
);
40614061
}
40624062

4063+
#[test]
4064+
fn index_unresolved_constant_references_in_default_values() {
4065+
let context = index_source({
4066+
"
4067+
def foo(a = C1, b = C2::C3); end
4068+
def bar(a: C4, b: C5::C6); end
4069+
"
4070+
});
4071+
4072+
assert_no_local_diagnostics!(&context);
4073+
assert_constant_references_eq!(&context, ["C1", "C2", "C3", "C4", "C5", "C6"]);
4074+
}
4075+
40634076
#[test]
40644077
fn index_constant_path_and_write_visits_value() {
40654078
let context = index_source({

0 commit comments

Comments
 (0)