Skip to content

Conversation

eileencodes
Copy link
Member

@eileencodes eileencodes commented Jan 28, 2025

When calling set_temporary_name on a parent module the child modules should get their name updated too.

Before:

m = Module.new
m::N = Module.new
p m::N.name # => "#<Module:0x000000010d0a00b0>::N"

m.set_temporary_name("foo")
p m::N.name # => "#<Module:0x000000010d0a00b0>::N"

After:

m = Module.new
m::N = Module.new
p m::N.name # => "#<Module:0x000000010d0a00b0>::N"

m.set_temporary_name("foo")
p m::N.name # => "foo::N"

[Bug #21094]

When calling `set_temporary_name` on a parent module the child modules
should get their name updated too.

Before:

```ruby
m = Module.new
m::N = Module.new
p m::N.name # => "#<Module:0x000000010d0a00b0>::N"

m.set_temporary_name("foo")
p m::N.name # => "#<Module:0x000000010d0a00b0>::N"
```

After:

```ruby
m = Module.new
m::N = Module.new
p m::N.name # => "#<Module:0x000000010d0a00b0>::N"

m.set_temporary_name("foo")
p m::N.name # => "foo::N"
```

[Bug #21094]
@nobu
Copy link
Member

nobu commented Jan 29, 2025

Shouldn’t this change too?

m = Module.new
m::N = Module.new
m::N::O = Module.new

m.set_temporary_name("foo")
p m::N::O

@eileencodes
Copy link
Member Author

Ah yea that should work too. I'll fix it tomorrow morning.

VALUE value = ce->value;
VALUE parental_path = *((VALUE *) payload);

rb_mod_set_temporary_name(value, build_const_path(parental_path, id));
Copy link
Member

Choose a reason for hiding this comment

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

If the anonymous module has a constant that is not anonymous class or module, this will raise an exception.
And will crash on a non-class/module constant.

@nobu
Copy link
Member

nobu commented Jan 29, 2025

set_temporary_name.patch

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.

3 participants