Project

General

Profile

Actions

Bug #21374

closed

FrozenError message is inconsistent when a singleton method is defined on a frozen object

Bug #21374: FrozenError message is inconsistent when a singleton method is defined on a frozen object

Added by andrykonchin (Andrew Konchin) 7 months ago. Updated 3 days ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:122296]

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 Actions #1

  • ruby -v set to 3.4.2

Updated by matz (Yukihiro Matsumoto) 6 months ago Actions #2 [ruby-core:122435]

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 Actions #3 [ruby-core:123886]

I submitted a pull request to fix this issue: https://github.com/ruby/ruby/pull/15303

Updated by jeremyevans (Jeremy Evans) 3 days ago Actions #4

  • 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]

Actions

Also available in: PDF Atom