Skip to content

Commit

Permalink
The clone method should copy object status (e.g. frozen) too; #4030
Browse files Browse the repository at this point in the history
  • Loading branch information
matz committed Jun 1, 2018
1 parent 7ed164b commit f408143
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ mrb_obj_clone(mrb_state *mrb, mrb_value self)
mrb_field_write_barrier(mrb, (struct RBasic*)p, (struct RBasic*)p->c);
clone = mrb_obj_value(p);
init_copy(mrb, clone, self);
p->flags = mrb_obj_ptr(self)->flags;

return clone;
}
Expand Down
4 changes: 4 additions & 0 deletions test/t/kernel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ def a.test
assert_true a.respond_to?(:test)
assert_false b.respond_to?(:test)
assert_true c.respond_to?(:test)

a.freeze
d = a.clone
assert_true d.frozen?
end

assert('Kernel#dup', '15.3.1.3.9') do
Expand Down

0 comments on commit f408143

Please sign in to comment.