[Bug #21819] Data objects without members should also be frozen

This commit is contained in:
Nobuyoshi Nakada 2026-01-03 15:03:57 +09:00
parent a8a989b6f6
commit d7a6ff8224
No known key found for this signature in database
GPG Key ID: 3582D74E1FEE4465
Notes: git 2026-01-03 06:45:26 +00:00
2 changed files with 2 additions and 0 deletions

View File

@ -1809,6 +1809,7 @@ rb_data_initialize_m(int argc, const VALUE *argv, VALUE self)
if (num_members > 0) {
rb_exc_raise(rb_keyword_error_new("missing", members));
}
OBJ_FREEZE(self);
return Qnil;
}
if (argc > 1 || !RB_TYPE_P(argv[0], T_HASH)) {

View File

@ -262,6 +262,7 @@ class TestData < Test::Unit::TestCase
assert_equal('#<data >', test.inspect)
assert_equal([], test.members)
assert_equal({}, test.to_h)
assert_predicate(test, :frozen?)
end
def test_dup