@@ -1194,31 +1194,33 @@ impl<'a> RubyIndexer<'a> {
11941194 fn handle_constant_visibility ( & mut self , node : & ruby_prism:: CallNode , visibility : Visibility ) {
11951195 let receiver = node. receiver ( ) ;
11961196
1197- let receiver_name_id = match receiver {
1197+ let receiver_name_id = match & receiver {
11981198 Some ( ruby_prism:: Node :: ConstantPathNode { .. } | ruby_prism:: Node :: ConstantReadNode { .. } ) => {
1199- self . index_constant_reference ( & receiver. unwrap ( ) , true )
1199+ self . index_constant_reference ( receiver. as_ref ( ) . unwrap ( ) , true )
12001200 }
12011201 Some ( ruby_prism:: Node :: SelfNode { .. } ) | None => match self . nesting_stack . last ( ) {
12021202 Some ( Nesting :: Method ( _) ) => {
12031203 self . visit_call_node_parts ( node) ;
12041204 return ;
12051205 }
12061206 None => {
1207+ let call_name = String :: from_utf8_lossy ( node. name ( ) . as_slice ( ) ) ;
12071208 self . local_graph . add_diagnostic (
12081209 Rule :: InvalidPrivateConstant ,
12091210 Offset :: from_prism_location ( & node. location ( ) ) ,
1210- "Private constant called at top level". to_string ( ) ,
1211+ format ! ( "`{call_name}` called at top level") ,
12111212 ) ;
12121213 self . visit_call_node_parts ( node) ;
12131214 return ;
12141215 }
12151216 _ => None ,
12161217 } ,
1217- _ => {
1218+ Some ( other) => {
1219+ let call_name = String :: from_utf8_lossy ( node. name ( ) . as_slice ( ) ) ;
12181220 self . local_graph . add_diagnostic (
12191221 Rule :: InvalidPrivateConstant ,
1220- Offset :: from_prism_location ( & node . location ( ) ) ,
1221- "Dynamic receiver for private constant" . to_string ( ) ,
1222+ Offset :: from_prism_location ( & other . location ( ) ) ,
1223+ format ! ( "Dynamic receiver for `{call_name}`" ) ,
12221224 ) ;
12231225 self . visit_call_node_parts ( node) ;
12241226 return ;
@@ -1230,29 +1232,14 @@ impl<'a> RubyIndexer<'a> {
12301232 } ;
12311233
12321234 for argument in & arguments. arguments ( ) {
1233- let ( name, location) = match argument {
1234- ruby_prism:: Node :: SymbolNode { .. } => {
1235- let symbol = argument. as_symbol_node ( ) . unwrap ( ) ;
1236- if let Some ( value_loc) = symbol. value_loc ( ) {
1237- ( Self :: location_to_string ( & value_loc) , value_loc)
1238- } else {
1239- continue ;
1240- }
1241- }
1242- ruby_prism:: Node :: StringNode { .. } => {
1243- let string = argument. as_string_node ( ) . unwrap ( ) ;
1244- let name = String :: from_utf8_lossy ( string. unescaped ( ) ) . to_string ( ) ;
1245- ( name, argument. location ( ) )
1246- }
1247- _ => {
1248- self . local_graph . add_diagnostic (
1249- Rule :: InvalidPrivateConstant ,
1250- Offset :: from_prism_location ( & argument. location ( ) ) ,
1251- "Private constant called with non-symbol argument" . to_string ( ) ,
1252- ) ;
1253- self . visit ( & argument) ;
1254- continue ;
1255- }
1235+ let Some ( ( name, location) ) = Self :: extract_literal_name ( & argument) else {
1236+ self . local_graph . add_diagnostic (
1237+ Rule :: InvalidPrivateConstant ,
1238+ Offset :: from_prism_location ( & argument. location ( ) ) ,
1239+ "Private constant called with non-symbol argument" . to_string ( ) ,
1240+ ) ;
1241+ self . visit ( & argument) ;
1242+ continue ;
12561243 } ;
12571244
12581245 let str_id = self . local_graph . intern_string ( name) ;
@@ -1414,6 +1401,22 @@ impl<'a> RubyIndexer<'a> {
14141401 }
14151402 }
14161403
1404+ fn extract_literal_name < ' b > ( arg : & ruby_prism:: Node < ' b > ) -> Option < ( String , ruby_prism:: Location < ' b > ) > {
1405+ match arg {
1406+ ruby_prism:: Node :: SymbolNode { .. } => {
1407+ let symbol = arg. as_symbol_node ( ) . unwrap ( ) ;
1408+ let value_loc = symbol. value_loc ( ) ?;
1409+ Some ( ( Self :: location_to_string ( & value_loc) , value_loc) )
1410+ }
1411+ ruby_prism:: Node :: StringNode { .. } => {
1412+ let string = arg. as_string_node ( ) . unwrap ( ) ;
1413+ let name = String :: from_utf8_lossy ( string. unescaped ( ) ) . to_string ( ) ;
1414+ Some ( ( name, arg. location ( ) ) )
1415+ }
1416+ _ => None ,
1417+ }
1418+ }
1419+
14171420 fn is_attr_call ( arg : & ruby_prism:: Node ) -> bool {
14181421 arg. as_call_node ( ) . is_some_and ( |call| {
14191422 let receiver = call. receiver ( ) ;
@@ -1473,18 +1476,8 @@ impl<'a> RubyIndexer<'a> {
14731476 visibility : Visibility ,
14741477 flags : DefinitionFlags ,
14751478 ) {
1476- let ( name, location) = match arg {
1477- ruby_prism:: Node :: SymbolNode { .. } => {
1478- let symbol = arg. as_symbol_node ( ) . unwrap ( ) ;
1479- let Some ( value_loc) = symbol. value_loc ( ) else { return } ;
1480- ( Self :: location_to_string ( & value_loc) , value_loc)
1481- }
1482- ruby_prism:: Node :: StringNode { .. } => {
1483- let string = arg. as_string_node ( ) . unwrap ( ) ;
1484- let name = String :: from_utf8_lossy ( string. unescaped ( ) ) . to_string ( ) ;
1485- ( name, arg. location ( ) )
1486- }
1487- _ => return ,
1479+ let Some ( ( name, location) ) = Self :: extract_literal_name ( arg) else {
1480+ return ;
14881481 } ;
14891482
14901483 self . create_method_visibility_definition_from_name ( & name, & location, visibility, flags) ;
0 commit comments