Skip to content

Commit 5872fd6

Browse files
committed
[Feature #19163] Marshal-loaded Data object also should be frozen
1 parent a14a1a5 commit 5872fd6

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

struct.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,7 @@ VALUE
786786
rb_struct_initialize(VALUE self, VALUE values)
787787
{
788788
rb_struct_initialize_m(RARRAY_LENINT(values), RARRAY_CONST_PTR(values), self);
789+
if (rb_obj_is_kind_of(self, rb_cData)) OBJ_FREEZE_RAW(self);
789790
RB_GC_GUARD(values);
790791
return Qnil;
791792
}

test/ruby/test_data.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,14 @@ def test_dup
177177
assert_equal(klass.new(foo: 1, bar: 2), test.dup)
178178
assert_predicate(test.dup, :frozen?)
179179
end
180+
181+
Klass = Data.define(:foo, :bar)
182+
183+
def test_marshal
184+
test = Klass.new(foo: 1, bar: 2)
185+
loaded = Marshal.load(Marshal.dump(test))
186+
assert_equal(test, loaded)
187+
assert_not_same(test, loaded)
188+
assert_predicate(loaded, :frozen?)
189+
end
180190
end

0 commit comments

Comments
 (0)