Skip to content

fix(module): clear temporary name when module assigned to constant in named parent - #9797

Open
reginaldalfret wants to merge 1 commit into
jruby:masterfrom
reginaldalfret:oss-fix/jruby-temporary-name-nesting
Open

reginaldalfret wants to merge 1 commit into
jruby:masterfrom
reginaldalfret:oss-fix/jruby-temporary-name-nesting

Conversation

@reginaldalfret

Copy link
Copy Markdown
Contributor

Description

Fixes #9680.

When a class or module with a temporary name (via \set_temporary_name) was subsequently assigned to a constant within a permanently-named outer module, the internal \TEMP_NAME\ flag was not being cleared. As a result, subsequent #name\ and #to_s\ calls continued treating the class as a temporary module and ignored outer nesting, producing e.g. \Subclass\ instead of \Namespace::Subclass.

Additionally, calling \set_temporary_name(nil)\ did not clear \TEMP_NAME, leaving the flag set even after resetting to anonymous.

Changes

  1. In \RubyModule#setParentForModule, only assign a permanent base name and clear \TEMP_NAME\ when the enclosing outer module itself has a permanent name (\getBaseName() != null && !usingTemporaryName()). This preserves temporary names when assigned into anonymous modules (per RubySpec), while properly assigning permanent names and nesting when assigned into named parent modules.
  2. In \RubyModule#set_temporary_name, clear \TEMP_NAME\ when called with
    il.
  3. Added a regression test in \ est/jruby/test_class.rb.

Signed-off-by: reginaldalfret reginaldalfret@gmail.com

… named parent

When a class or module with a temporary name (via set_temporary_name) is subsequently assigned to a constant within a permanently-named outer module, the TEMP_NAME flag was not being cleared, causing subsequent #name and #to_s calls to continue treating the class as temporary and ignoring outer nesting. Additionally, calling set_temporary_name(nil) did not clear TEMP_NAME.

Only assign a permanent base name and clear TEMP_NAME when the enclosing outer module has a permanent name, preserving temporary names when nested inside anonymous modules per RubySpec.

Fixes jruby#9680

Signed-off-by: reginaldalfret <reginaldalfret@gmail.com>
@kares

kares commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

Hey Reginald, looks good. Out of curiosity, are you using a LLM, if so which?
Feels a bit clinky around text escapes. 😉

@headius headius left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good but the test should go under spec/ruby as part of RubySpec (it is testing standard Ruby behavior).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using set_temporary_name makes Class#name ignore nesting

3 participants