Makes the receiver to FrozenError.new a keyword parameter
[Feature #16419]
This commit is contained in:
parent
216b62aa87
commit
435a4ca2a3
23
error.c
23
error.c
@ -1431,9 +1431,16 @@ exit_success_p(VALUE exc)
|
|||||||
return Qfalse;
|
return Qfalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
err_init_recv(VALUE exc, VALUE recv)
|
||||||
|
{
|
||||||
|
if (recv != Qundef) rb_ivar_set(exc, id_recv, recv);
|
||||||
|
return exc;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* FrozenError.new(msg=nil, receiver=nil) -> frozen_error
|
* FrozenError.new(msg=nil, receiver: nil) -> frozen_error
|
||||||
*
|
*
|
||||||
* Construct a new FrozenError exception. If given the <i>receiver</i>
|
* Construct a new FrozenError exception. If given the <i>receiver</i>
|
||||||
* parameter may subsequently be examined using the FrozenError#receiver
|
* parameter may subsequently be examined using the FrozenError#receiver
|
||||||
@ -1446,14 +1453,14 @@ exit_success_p(VALUE exc)
|
|||||||
static VALUE
|
static VALUE
|
||||||
frozen_err_initialize(int argc, VALUE *argv, VALUE self)
|
frozen_err_initialize(int argc, VALUE *argv, VALUE self)
|
||||||
{
|
{
|
||||||
VALUE mesg, recv;
|
ID keywords[1];
|
||||||
|
VALUE values[numberof(keywords)], options;
|
||||||
|
|
||||||
argc = rb_scan_args(argc, argv, "02", &mesg, &recv);
|
argc = rb_scan_args(argc, argv, "*:", NULL, &options);
|
||||||
if (argc > 1) {
|
keywords[0] = id_receiver;
|
||||||
argc--;
|
rb_get_kwargs(options, keywords, 0, numberof(values), values);
|
||||||
rb_ivar_set(self, id_recv, recv);
|
|
||||||
}
|
|
||||||
rb_call_super(argc, argv);
|
rb_call_super(argc, argv);
|
||||||
|
err_init_recv(self, values[0]);
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1503,7 +1510,7 @@ name_err_init_attr(VALUE exc, VALUE recv, VALUE method)
|
|||||||
rb_control_frame_t *cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(ec->cfp);
|
rb_control_frame_t *cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(ec->cfp);
|
||||||
cfp = rb_vm_get_ruby_level_next_cfp(ec, cfp);
|
cfp = rb_vm_get_ruby_level_next_cfp(ec, cfp);
|
||||||
rb_ivar_set(exc, id_name, method);
|
rb_ivar_set(exc, id_name, method);
|
||||||
if (recv != Qundef) rb_ivar_set(exc, id_recv, recv);
|
err_init_recv(exc, recv);
|
||||||
if (cfp) rb_ivar_set(exc, id_iseq, rb_iseqw_new(cfp->iseq));
|
if (cfp) rb_ivar_set(exc, id_iseq, rb_iseqw_new(cfp->iseq));
|
||||||
return exc;
|
return exc;
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ describe "FrozenError.new" do
|
|||||||
ruby_version_is "2.7" do
|
ruby_version_is "2.7" do
|
||||||
it "should take optional receiver argument" do
|
it "should take optional receiver argument" do
|
||||||
o = Object.new
|
o = Object.new
|
||||||
FrozenError.new("msg", o).receiver.should equal(o)
|
FrozenError.new("msg", receiver: o).receiver.should equal(o)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -845,7 +845,7 @@ end.join
|
|||||||
|
|
||||||
def test_frozen_error_initialize
|
def test_frozen_error_initialize
|
||||||
obj = Object.new
|
obj = Object.new
|
||||||
exc = FrozenError.new("bar", obj)
|
exc = FrozenError.new("bar", receiver: obj)
|
||||||
assert_equal("bar", exc.message)
|
assert_equal("bar", exc.message)
|
||||||
assert_same(obj, exc.receiver)
|
assert_same(obj, exc.receiver)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user