Project

General

Profile

Actions

Bug #19681

closed

The final classpath of partially named modules is sometimes inconsistent once permanently named

Added by byroot (Jean Boussier) over 1 year ago. Updated over 1 year ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:113529]

Description

Reported to me by @fxn (Xavier Noria)

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"

Expected behavior:

p M::C.name # => "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.


Related issues 1 (0 open1 closed)

Related to Ruby master - Feature #15765: [PATCH] Module#name without global constant searchClosedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like1Like0Like1Like0Like0Like0Like0Like0Like0