From f575ccc64f68a6484246c7bc73b42b3cf4c5bd1d Mon Sep 17 00:00:00 2001 From: nobu Date: Sun, 25 Mar 2018 02:22:14 +0000 Subject: vm_args.c: warn splat to var * vm_args.c (setup_parameters_complex): [EXPERIMENTAL] warn when splat keyword arguments is passed as a single ordinary argument, not as a keyword rest argument. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62914 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- vm_args.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'vm_args.c') diff --git a/vm_args.c b/vm_args.c index d1207f7f62..c5a83b9946 100644 --- a/vm_args.c +++ b/vm_args.c @@ -509,6 +509,7 @@ setup_parameters_complex(rb_execution_context_t * const ec, const rb_iseq_t * co const int max_argc = (iseq->body->param.flags.has_rest == FALSE) ? min_argc + iseq->body->param.opt_num : UNLIMITED_ARGUMENTS; int opt_pc = 0; int given_argc; + int kw_splat = FALSE; struct args_info args_body, *args; VALUE keyword_hash = Qnil; VALUE * const orig_sp = ec->cfp->sp; @@ -600,10 +601,12 @@ setup_parameters_complex(rb_execution_context_t * const ec, const rb_iseq_t * co } } + if (ci->flag & VM_CALL_KW_SPLAT) { + kw_splat = !iseq->body->param.flags.has_rest; + } if (given_argc > min_argc && (iseq->body->param.flags.has_kw || iseq->body->param.flags.has_kwrest || - (!iseq->body->param.flags.has_rest && given_argc > max_argc && - (ci->flag & VM_CALL_KW_SPLAT))) && + (kw_splat && given_argc > max_argc)) && args->kw_argv == NULL) { if (args_pop_keyword_hash(args, &keyword_hash)) { given_argc--; @@ -667,6 +670,10 @@ setup_parameters_complex(rb_execution_context_t * const ec, const rb_iseq_t * co else if (!NIL_P(keyword_hash) && RHASH_SIZE(keyword_hash) > 0) { argument_kw_error(ec, iseq, "unknown", rb_hash_keys(keyword_hash)); } + else if (kw_splat && NIL_P(keyword_hash)) { + rb_warning("passing splat keyword arguments as a single Hash" + " to `% "PRIsVALUE"'", rb_id2str(ci->mid)); + } if (iseq->body->param.flags.has_block) { if (iseq->body->local_iseq == iseq) { -- cgit v1.2.3