Actions
Bug #21282
closed`FrozenError` raised by `rb_error_frozen_object` should mention real class of frozen object
Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.5.0dev (2025-04-23T14:19:58Z fix-frozenerror-me.. 5c9dd42e27) +PRISM [x86_64-darwin24]
Description
Hello everyone,
I've noticed that the following snippets both raise FrozenError
, but with different messages:
Object.new.freeze.instance_variable_set(:@test, true) # can't modify frozen Object: #<Object:0x000000010b4d8aa8> (FrozenError)
Object.new.freeze.tap(&:singleton_class).instance_variable_set(:@test, true) # can't modify frozen #<Class:#<Object:0x0000000101538a98>>: #<Object:0x0000000101538a98> (FrozenError)
As you can see, the second example mentions the singleton class of the object, while I would expect Object
to be mentioned in its place, as the first example does.
From what I can see in test/ruby/test_frozen_error.rb
, the expected behavior here should be to display the real class of the frozen object (as returned by Kernel#class
), independently of the existence of a singleton class.
I'm working on a PR that should fix this (will post the link in the comments in a moment).
Cheers!
Actions
Like0
Like0Like0Like0