Project

General

Profile

Bug #11636 ยป instance_eval-module-super-11636.patch

jeremyevans0 (Jeremy Evans), 08/21/2019 09:12 PM

View differences:

class.c
}
iclass = rb_include_class_new(module, RCLASS_SUPER(c));
c = RCLASS_SET_SUPER(c, iclass);
RCLASS_SET_INCLUDER(iclass, klass);
{
VALUE m = module;
internal.h
const VALUE origin_;
const VALUE refined_class;
rb_alloc_func_t allocator;
const VALUE includer;
};
typedef struct rb_classext_struct rb_classext_t;
......
#define RCLASS_ORIGIN(c) (RCLASS_EXT(c)->origin_)
#define RCLASS_REFINED_CLASS(c) (RCLASS_EXT(c)->refined_class)
#define RCLASS_SERIAL(c) (RCLASS_EXT(c)->class_serial)
#define RCLASS_INCLUDER(c) (RCLASS_EXT(c)->includer)
#define RCLASS_CLONED FL_USER6
#define RICLASS_IS_ORIGIN FL_USER5
......
if (klass != origin) FL_SET(origin, RICLASS_IS_ORIGIN);
}
static inline void
RCLASS_SET_INCLUDER(VALUE iclass, VALUE klass)
{
RB_OBJ_WRITE(iclass, &RCLASS_INCLUDER(iclass), klass);
}
#undef RCLASS_SUPER
static inline VALUE
RCLASS_SUPER(VALUE klass)
test/ruby/test_super.rb
end
end
def test_super_in_instance_eval_in_module
super_class = EnvUtil.labeled_class("Super\u{30af 30e9 30b9}") {
def foo
return [:super, self]
end
}
mod = EnvUtil.labeled_module("Mod\u{30af 30e9 30b9}") {
def foo
x = Object.new
x.instance_eval do
super()
end
end
}
sub_class = EnvUtil.labeled_class("Sub\u{30af 30e9 30b9}", super_class) {
include mod
}
obj = sub_class.new
assert_raise_with_message(TypeError, /Sub\u{30af 30e9 30b9}/) do
obj.foo
end
end
def test_super_in_orphan_block
super_class = EnvUtil.labeled_class("Super\u{30af 30e9 30b9}") {
def foo
vm_insnhelper.c
}
if (BUILTIN_TYPE(current_defined_class) != T_MODULE &&
BUILTIN_TYPE(current_defined_class) != T_ICLASS && /* bound UnboundMethod */
!FL_TEST(current_defined_class, RMODULE_INCLUDED_INTO_REFINEMENT) &&
!rb_obj_is_kind_of(recv, current_defined_class)) {
VALUE m = RB_TYPE_P(current_defined_class, T_ICLASS) ?
RBASIC(current_defined_class)->klass : current_defined_class;
RCLASS_INCLUDER(current_defined_class) : current_defined_class;
rb_raise(rb_eTypeError,
"self has wrong type to call super in this context: "
"%"PRIsVALUE" (expected %"PRIsVALUE")",
rb_obj_class(recv), m);
if (m) { /* not bound UnboundMethod */
rb_raise(rb_eTypeError,
"self has wrong type to call super in this context: "
"%"PRIsVALUE" (expected %"PRIsVALUE")",
rb_obj_class(recv), m);
}
}
if (me->def->type == VM_METHOD_TYPE_BMETHOD && (ci->flag & VM_CALL_ZSUPER)) {
    (1-1/1)