diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-12-20 14:14:07 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-12-20 14:18:20 +0900 |
commit | 435a4ca2a38f3be1f5d2db0f71487a52c8285e9c (patch) | |
tree | 11388cf5f47b7944287db1388c86eb176a019593 /error.c | |
parent | 216b62aa87f069c51085e9f9abb548930370bc53 (diff) | |
download | ruby-435a4ca2a38f3be1f5d2db0f71487a52c8285e9c.tar.gz |
Makes the receiver to FrozenError.new a keyword parameter
[Feature #16419]
Diffstat (limited to 'error.c')
-rw-r--r-- | error.c | 23 |
1 files changed, 15 insertions, 8 deletions
@@ -1431,9 +1431,16 @@ exit_success_p(VALUE exc) 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: - * 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> * parameter may subsequently be examined using the FrozenError#receiver @@ -1446,14 +1453,14 @@ exit_success_p(VALUE exc) static VALUE 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); - if (argc > 1) { - argc--; - rb_ivar_set(self, id_recv, recv); - } + argc = rb_scan_args(argc, argv, "*:", NULL, &options); + keywords[0] = id_receiver; + rb_get_kwargs(options, keywords, 0, numberof(values), values); rb_call_super(argc, argv); + err_init_recv(self, values[0]); 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); cfp = rb_vm_get_ruby_level_next_cfp(ec, cfp); 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)); return exc; } |