Project

General

Profile

Bug #19681

Updated by Eregon (Benoit Daloze) about 1 year ago

Reported to me by @fxn  

 ```ruby 
 m = Module.new 

 class m::C; end 
 p m::C.name # => "#<Module:0x000000010789fbe0>::C" 

 m::D = m::C 
 p m::D.name # => "#<Module:0x000000010789fbe0>::C" 

 M = m 
 p M::C.name # => "M::D" "#<M::D" 
 ``` 

 Expected behavior: 

 ```ruby 
 p M::C.name # => "M::C" "#<M::C" 
 ``` 

 ### Reason 

 When the parent is assigned its permanent classpath, we iterate over its `const_table` to recursively give a permanent name to all the constant it owns. 

 However, `const_table` is an `id_table` so it doesn't retain the insertion order, which means that if the constant was aliased, 
 we can no longer distinguish between the original name and its aliases, and whichever comes first in the `const_table` will be used as the permanent name. 

 ### Potential solution 

 I have a tentative fix for it in https://github.com/ruby/ruby/pull/7829. Instead of relying on the `const_table` key, it extract the original name from the temporary classpath. 
 It does feel a bit wrong to do a string search in such a place, but it does work. 

 

Back