File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -495,7 +495,10 @@ impl Visit for RBSIndexer<'_> {
495495 self . uri_id ,
496496 offset,
497497 comments,
498- Self :: flags ( & constant_node. annotations ( ) ) ,
498+ // RBS establishes that the constant exists, but its value type is intentionally not
499+ // represented in the graph. Treat it like a dynamic Ruby assignment so resolution
500+ // may promote it when a namespace or singleton receiver is required.
501+ Self :: flags ( & constant_node. annotations ( ) ) | DefinitionFlags :: PROMOTABLE ,
499502 lexical_nesting_id,
500503 ) ) ) ;
501504
Original file line number Diff line number Diff line change @@ -4624,6 +4624,33 @@ mod promotability_tests {
46244624 assert_declaration_does_not_exist ! ( context, "Foo::<Foo>#bar()" ) ;
46254625 }
46264626
4627+ #[ test]
4628+ fn rbs_constant_is_promotable_for_singleton_call ( ) {
4629+ let mut context = graph_test ( ) ;
4630+ context. index_rbs_uri ( "file:///env.rbs" , "ENV: untyped" ) ;
4631+ context. index_uri ( "file:///env.rb" , {
4632+ r#"
4633+ ENV.fetch("FEATURE")
4634+ "#
4635+ } ) ;
4636+ context. resolve ( ) ;
4637+
4638+ assert_no_diagnostics ! ( & context) ;
4639+ assert_declaration_exists ! ( context, "ENV::<ENV>" ) ;
4640+
4641+ let fetch = context
4642+ . graph ( )
4643+ . method_references ( )
4644+ . values ( )
4645+ . find ( |method| * method. str ( ) == "fetch" . into ( ) )
4646+ . expect ( "ENV.fetch should be indexed" ) ;
4647+ let receiver_name_id = fetch. receiver ( ) . expect ( "ENV.fetch should have a receiver" ) ;
4648+ let NameRef :: Resolved ( receiver) = context. graph ( ) . names ( ) . get ( & receiver_name_id) . unwrap ( ) else {
4649+ panic ! ( "ENV.fetch receiver should resolve" ) ;
4650+ } ;
4651+ assert_eq ! ( * receiver. declaration_id( ) , DeclarationId :: from( "ENV::<ENV>" ) ) ;
4652+ }
4653+
46274654 #[ test]
46284655 fn ivar_defined_inside_of_undefined_alias_namespace ( ) {
46294656 let mut context = graph_test ( ) ;
You can’t perform that action at this time.
0 commit comments