зеркало из https://github.com/github/ruby.git
[Feature #19163] Marshal-loaded Data object also should be frozen
This commit is contained in:
Родитель
a14a1a5626
Коммит
5872fd6f6c
1
struct.c
1
struct.c
|
@ -786,6 +786,7 @@ VALUE
|
|||
rb_struct_initialize(VALUE self, VALUE values)
|
||||
{
|
||||
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);
|
||||
return Qnil;
|
||||
}
|
||||
|
|
|
@ -177,4 +177,14 @@ class TestData < Test::Unit::TestCase
|
|||
assert_equal(klass.new(foo: 1, bar: 2), test.dup)
|
||||
assert_predicate(test.dup, :frozen?)
|
||||
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
|
||||
|
|
Загрузка…
Ссылка в новой задаче