Bug #21374
closedFrozenError message is inconsistent when a singleton method is defined on a frozen object
Description
I would expect a message to contain an object class (e.g. can't modify frozen <class>: <object#inspect>) when an ordinary frozen object (non a module or class) is being modified. It works this way in the following example:
object = []; object.freeze; object.instance_variable_set(:@a, 42)
# (irb):5:in `instance_variable_set': can't modify frozen Array: [] (FrozenError)
But it doesn't in the following example:
object = []; object.freeze; def object.x; end
# (irb):4:in `<main>': can't modify frozen object: [] (FrozenError)
Updated by andrykonchin (Andrew Konchin) 7 months ago
- ruby -v set to 3.4.2
Updated by matz (Yukihiro Matsumoto) 6 months ago
I agree with you. It should be consistent (and I prefer can't modify frozen Array: [] (FrozenError) message). But there might be some internal reason. We have to investigate first.
Matz.
Updated by jeremyevans0 (Jeremy Evans) 20 days ago
I submitted a pull request to fix this issue: https://github.com/ruby/ruby/pull/15303
Updated by jeremyevans (Jeremy Evans) 3 days ago
- Status changed from Open to Closed
Applied in changeset git|e436dba9fee4c75104212ad0fd16ab7f753985c4.
Use rb_error_frozen_object in rb_class_modify_check
This provides information on the class of the frozen object. It also
results in a much simpler implementation.
Fixes [Bug #21374]