[Feature #19163] Marshal-loaded Data object also should be frozen

This commit is contained in:
Nobuyoshi Nakada 2022-12-01 22:50:25 +09:00
Родитель a14a1a5626
Коммит 5872fd6f6c
2 изменённых файлов: 11 добавлений и 0 удалений

Просмотреть файл

@ -786,6 +786,7 @@ VALUE
rb_struct_initialize(VALUE self, VALUE values) rb_struct_initialize(VALUE self, VALUE values)
{ {
rb_struct_initialize_m(RARRAY_LENINT(values), RARRAY_CONST_PTR(values), self); rb_struct_initialize_m(RARRAY_LENINT(values), RARRAY_CONST_PTR(values), self);
if (rb_obj_is_kind_of(self, rb_cData)) OBJ_FREEZE_RAW(self);
RB_GC_GUARD(values); RB_GC_GUARD(values);
return Qnil; return Qnil;
} }

Просмотреть файл

@ -177,4 +177,14 @@ class TestData < Test::Unit::TestCase
assert_equal(klass.new(foo: 1, bar: 2), test.dup) assert_equal(klass.new(foo: 1, bar: 2), test.dup)
assert_predicate(test.dup, :frozen?) assert_predicate(test.dup, :frozen?)
end end
Klass = Data.define(:foo, :bar)
def test_marshal
test = Klass.new(foo: 1, bar: 2)
loaded = Marshal.load(Marshal.dump(test))
assert_equal(test, loaded)
assert_not_same(test, loaded)
assert_predicate(loaded, :frozen?)
end
end end