mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Singleton class of frozen object should be frozen
Before this patch: p (class << Object.new.freeze; self end).frozen? #=> false sc = class << (o=Object.new); self end; o.freeze; p sc.frozen? #=> false After this patch / Ruby: p (class << Object.new.freeze; self end).frozen? #=> true sc = class << (o=Object.new); self end; o.freeze; p sc.frozen? #=> true
This commit is contained in:
@@ -120,6 +120,7 @@ prepare_singleton_class(mrb_state *mrb, struct RBasic *o)
|
||||
mrb_field_write_barrier(mrb, (struct RBasic*)o, (struct RBasic*)sc);
|
||||
mrb_field_write_barrier(mrb, (struct RBasic*)sc, (struct RBasic*)o);
|
||||
mrb_obj_iv_set(mrb, (struct RObject*)sc, mrb_intern_lit(mrb, "__attached__"), mrb_obj_value(o));
|
||||
sc->flags |= o->flags & MRB_FL_OBJ_IS_FROZEN;
|
||||
}
|
||||
|
||||
static mrb_value
|
||||
|
||||
@@ -438,6 +438,7 @@ mrb_obj_freeze(mrb_state *mrb, mrb_value self)
|
||||
struct RBasic *b = mrb_basic_ptr(self);
|
||||
if (!MRB_FROZEN_P(b)) {
|
||||
MRB_SET_FROZEN_FLAG(b);
|
||||
if (b->c->tt == MRB_TT_SCLASS) MRB_SET_FROZEN_FLAG(b->c);
|
||||
}
|
||||
}
|
||||
return self;
|
||||
|
||||
Reference in New Issue
Block a user