Project

General

Profile

Bug #7572 » defineclass_fix.diff

shugo (Shugo Maeda), 12/17/2012 11:00 PM

View differences:

compile.c
rb_sprintf("<class:%s>", rb_id2name(node->nd_cpath->nd_mid)),
ISEQ_TYPE_CLASS, nd_line(node));
VALUE noscope = compile_cpath(ret, iseq, node->nd_cpath);
int define_type = (noscope ? 3 : 0) | (node->nd_super ? 0x10 : 0);
COMPILE(ret, "super", node->nd_super);
ADD_INSN3(ret, nd_line(node), defineclass,
ID2SYM(node->nd_cpath->nd_mid), iseqval, INT2FIX(noscope ? 3 : 0));
ID2SYM(node->nd_cpath->nd_mid), iseqval, INT2FIX(define_type));
if (poped) {
ADD_INSN(ret, nd_line(node), pop);
insns.def
(VALUE val)
{
VALUE klass;
int type = define_type & 0x0F;
int super_specified = define_type & 0x10;
switch ((int)define_type) {
switch (type) {
case 0: /* scoped: class Foo::Bar */
case 3: /* no scope: class Bar */
/* val is dummy. classdef returns class scope value */
if (super_specified) {
if (!RB_TYPE_P(super, T_CLASS)) {
rb_raise(rb_eTypeError, "superclass must be a Class (%s given)",
rb_obj_classname(super));
}
}
if (super == Qnil) {
super = rb_cObject;
}
test/ruby/test_class.rb
assert_equal 1, m::C
assert_equal 1, m.m
end
def test_invalid_superclass
assert_raise(TypeError) do
eval <<-EOF
class C < nil
end
EOF
end
assert_raise(TypeError) do
eval <<-EOF
class C < false
end
EOF
end
end
end
(1-1/2)