summaryrefslogtreecommitdiff
path: root/vm_insnhelper.c
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2019-09-05 12:43:06 -0700
committerJeremy Evans <code@jeremyevans.net>2019-09-05 17:47:12 -0700
commite2878a96f77978b224f8461244cd3e1efc248d83 (patch)
tree197d7ed623eccc12adf5fa89057c7f6b1712b747 /vm_insnhelper.c
parente7274a8ec43b5b20e42842e730dbabae58d2e6a2 (diff)
Convert empty keyword hash to required positional argument and warn for lambda and bmethod
The lambda case is similar to the attr_writer case, except we have to determine the number of required parameters from the iseq instead of being able to assume a single required parameter. This fixes a lot of lambda tests which were switched to require warnings for all usage of keyword arguments. Similar to method handling, we do not warn when passing keyword arguments to lambdas that do not accept keyword arguments, the argument is just passed as a positional hash in that case, unless it is empty. If it is empty and not the final required parameter, then we ignore it. If it is empty and the final required parameter, then we pass it for backwards compatibility and emit a warning, as in Ruby 3 we will not pass it. The bmethod case is similar to the send case, in that we do not want to remove empty keyword splats in vm_call_bmethod, as that prevents later call handling from moving them to required positional arguments and warning.
Diffstat (limited to 'vm_insnhelper.c')
-rw-r--r--vm_insnhelper.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index fe333d1ea1..b1ea71a828 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -2294,7 +2294,7 @@ vm_call_bmethod(rb_execution_context_t *ec, rb_control_frame_t *cfp, struct rb_c
VALUE *argv;
int argc;
- CALLER_SETUP_ARG(cfp, calling, ci);
+ CALLER_SETUP_ARG_WITHOUT_KW_SPLAT(cfp, calling, ci);
argc = calling->argc;
argv = ALLOCA_N(VALUE, argc);
MEMCPY(argv, cfp->sp - argc, VALUE, argc);
@@ -2949,11 +2949,13 @@ vm_callee_setup_block_arg(rb_execution_context_t *ec, struct rb_calling_info *ca
rb_control_frame_t *cfp = ec->cfp;
VALUE arg0;
- CALLER_SETUP_ARG(cfp, calling, ci);
-
- if (calling->kw_splat) {
+ if (calling->kw_splat && calling->argc == iseq->body->param.lead_num + iseq->body->param.post_num && RHASH_EMPTY_P(cfp->sp[-1])) {
+ CALLER_SETUP_ARG_WITHOUT_KW_SPLAT(cfp, calling, ci);
rb_warn_keyword_to_last_hash(calling, ci, iseq);
}
+ else {
+ CALLER_SETUP_ARG(cfp, calling, ci);
+ }
if (arg_setup_type == arg_setup_block &&
calling->argc == 1 &&