Do not show an anonymous class as a receiver
This commit is contained in:
parent
0da12fa34e
commit
a7718c914a
@ -428,4 +428,23 @@ class TestBacktrace < Test::Unit::TestCase
|
|||||||
enum.next
|
enum.next
|
||||||
end;
|
end;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_no_receiver_for_anonymous_class
|
||||||
|
err = ["-:2:in 'bar': unhandled exception", # Not '#<Class:0xXXX>.bar'
|
||||||
|
"\tfrom -:3:in '<main>'"]
|
||||||
|
assert_in_out_err([], <<-"end;", [], err)
|
||||||
|
foo = Class.new
|
||||||
|
def foo.bar = raise
|
||||||
|
foo.bar
|
||||||
|
end;
|
||||||
|
|
||||||
|
err = ["-:3:in 'baz': unhandled exception", # Not '#<Class:0xXXX>::Bar.baz'
|
||||||
|
"\tfrom -:4:in '<main>'"]
|
||||||
|
assert_in_out_err([], <<-"end;", [], err)
|
||||||
|
foo = Class.new
|
||||||
|
foo::Bar = Class.new
|
||||||
|
def (foo::Bar).baz = raise
|
||||||
|
foo::Bar.baz
|
||||||
|
end;
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -111,6 +111,12 @@ classname(VALUE klass, bool *permanent)
|
|||||||
return classpath;
|
return classpath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VALUE
|
||||||
|
rb_mod_name0(VALUE klass, bool *permanent)
|
||||||
|
{
|
||||||
|
return classname(klass, permanent);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* mod.name -> string
|
* mod.name -> string
|
||||||
|
@ -191,22 +191,25 @@ location_lineno_m(VALUE self)
|
|||||||
return INT2FIX(location_lineno(location_ptr(self)));
|
return INT2FIX(location_lineno(location_ptr(self)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VALUE rb_mod_name0(VALUE klass, bool *permanent);
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
gen_method_name(VALUE owner, VALUE name)
|
gen_method_name(VALUE owner, VALUE name)
|
||||||
{
|
{
|
||||||
|
bool permanent;
|
||||||
if (RB_TYPE_P(owner, T_CLASS) || RB_TYPE_P(owner, T_MODULE)) {
|
if (RB_TYPE_P(owner, T_CLASS) || RB_TYPE_P(owner, T_MODULE)) {
|
||||||
if (RBASIC(owner)->flags & FL_SINGLETON) {
|
if (RBASIC(owner)->flags & FL_SINGLETON) {
|
||||||
VALUE v = RCLASS_ATTACHED_OBJECT(owner);
|
VALUE v = RCLASS_ATTACHED_OBJECT(owner);
|
||||||
if (RB_TYPE_P(v, T_CLASS) || RB_TYPE_P(v, T_MODULE)) {
|
if (RB_TYPE_P(v, T_CLASS) || RB_TYPE_P(v, T_MODULE)) {
|
||||||
v = rb_class_path(v);
|
v = rb_mod_name0(v, &permanent);
|
||||||
if (!NIL_P(v)) {
|
if (permanent && !NIL_P(v)) {
|
||||||
return rb_sprintf("%"PRIsVALUE".%"PRIsVALUE, v, name);
|
return rb_sprintf("%"PRIsVALUE".%"PRIsVALUE, v, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
owner = rb_class_path(owner);
|
owner = rb_mod_name0(owner, &permanent);
|
||||||
if (!NIL_P(owner)) {
|
if (permanent && !NIL_P(owner)) {
|
||||||
return rb_sprintf("%"PRIsVALUE"#%"PRIsVALUE, owner, name);
|
return rb_sprintf("%"PRIsVALUE"#%"PRIsVALUE, owner, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user