Skip to content

Commit d7a6ff8

Browse files
committed
[Bug #21819] Data objects without members should also be frozen
1 parent a8a989b commit d7a6ff8

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

struct.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,6 +1809,7 @@ rb_data_initialize_m(int argc, const VALUE *argv, VALUE self)
18091809
if (num_members > 0) {
18101810
rb_exc_raise(rb_keyword_error_new("missing", members));
18111811
}
1812+
OBJ_FREEZE(self);
18121813
return Qnil;
18131814
}
18141815
if (argc > 1 || !RB_TYPE_P(argv[0], T_HASH)) {

test/ruby/test_data.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ def test_memberless
262262
assert_equal('#<data >', test.inspect)
263263
assert_equal([], test.members)
264264
assert_equal({}, test.to_h)
265+
assert_predicate(test, :frozen?)
265266
end
266267

267268
def test_dup

0 commit comments

Comments
 (0)