Project

General

Profile

Actions

Misc #20944

closed

Module#set_temporary_name(nil) doesn't remove completely effect of a previous assigning a temporary name

Added by andrykonchin (Andrew Konchin) 5 months ago. Updated 5 months ago.

Status:
Closed
Assignee:
-
[ruby-core:120177]

Description

The method Module#set_temporary_namewas introduced in Ruby 3.3. I've noticed a surprising behaviour when a temporary name is assigned to an anonymous module (that has nested non-anonymous modules) and thenModule#set_temporary_namecalled withnil. The name of the nested module initially was fully qualified (e.g. #Module:0x000000010cc5a280::N) but after set_temporary_name(nil)call it becomesnil`.

Example (from ruby/spec):

m = Module.new
module m::N; end
m::N.name # => #<Module:0x...>::N

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

m::N.set_temporary_name(nil)
m::N.name # => nil               <==== questionable behaviour

I would expect a nested module name to have the initial value #<Module:0x000000010cc5a280>::N at the end.

The documentation states:

If the given name is nil, the module becomes anonymous again.

So I would expect all the effects of setting a (non-nil) temporary name should be also rolled back.

Linked issue https://bugs.ruby-lang.org/issues/19521

Actions #1

Updated by andrykonchin (Andrew Konchin) 5 months ago

  • Description updated (diff)

Updated by andrykonchin (Andrew Konchin) 5 months ago ยท Edited

  • Subject changed from Module#set_temporary_name(nil) doesn't remove completely effect of a previous assigning a temporary name to ~~Module#set_temporary_name(nil) doesn't remove completely effect of a previous assigning a temporary name~~
  • Description updated (diff)

Could you please close this issue?

I have misread the code and an object on which set_temporary_name is called (nested module, but not the outer). So the current behaviour is completely expected.

Actions #3

Updated by andrykonchin (Andrew Konchin) 5 months ago

  • Subject changed from ~~Module#set_temporary_name(nil) doesn't remove completely effect of a previous assigning a temporary name~~ to Module#set_temporary_name(nil) doesn't remove completely effect of a previous assigning a temporary name
  • Description updated (diff)
Actions #4

Updated by byroot (Jean Boussier) 5 months ago

  • Status changed from Open to Closed
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0