aboutsummaryrefslogtreecommitdiffstats
path: root/vm_args.c
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2019-08-30 19:23:10 -0700
committerJeremy Evans <code@jeremyevans.net>2019-08-30 19:25:46 -0700
commit3463e83192215c36bdcebad8be907eaa09593a41 (patch)
tree8289f8b226d72dc1540827229bfbfbb53282180f /vm_args.c
parent6424d316b993ecceb6f583ae476096274e304788 (diff)
downloadruby-3463e83192215c36bdcebad8be907eaa09593a41.tar.gz
Warn for keyword to last hash parameter when method has no optional/rest parameters
Previously, there was no warning in this case, even though we will be changing the behavior in Ruby 3. Fixes [Bug #14130]
Diffstat (limited to 'vm_args.c')
-rw-r--r--vm_args.c64
1 files changed, 34 insertions, 30 deletions
diff --git a/vm_args.c b/vm_args.c
index cd55f7d01d..f8d329c993 100644
--- a/vm_args.c
+++ b/vm_args.c
@@ -756,41 +756,45 @@ setup_parameters_complex(rb_execution_context_t * const ec, const rb_iseq_t * co
if (kw_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 ||
+ if ((iseq->body->param.flags.has_kw || iseq->body->param.flags.has_kwrest ||
(kw_splat && given_argc > max_argc)) &&
args->kw_argv == NULL) {
- if (((kw_flag & (VM_CALL_KWARG | VM_CALL_KW_SPLAT)) || !ec->cfp->iseq /* called from C */)) {
- int check_only_symbol = (kw_flag & VM_CALL_KW_SPLAT) &&
- iseq->body->param.flags.has_kw &&
- !iseq->body->param.flags.has_kwrest;
-
- if (args_pop_keyword_hash(args, &keyword_hash, check_only_symbol)) {
- given_argc--;
- }
- else if (check_only_symbol) {
- if (keyword_hash != Qnil) {
- rb_warn_split_last_hash_to_keyword(calling, ci);
+ if (given_argc > min_argc) {
+ if (((kw_flag & (VM_CALL_KWARG | VM_CALL_KW_SPLAT)) || !ec->cfp->iseq /* called from C */)) {
+ int check_only_symbol = (kw_flag & VM_CALL_KW_SPLAT) &&
+ iseq->body->param.flags.has_kw &&
+ !iseq->body->param.flags.has_kwrest;
+
+ if (args_pop_keyword_hash(args, &keyword_hash, check_only_symbol)) {
+ given_argc--;
}
- else {
- rb_warn_keyword_to_last_hash(calling, ci);
+ else if (check_only_symbol) {
+ if (keyword_hash != Qnil) {
+ rb_warn_split_last_hash_to_keyword(calling, ci);
+ }
+ else {
+ rb_warn_keyword_to_last_hash(calling, ci);
+ }
}
}
- }
- else if (args_pop_keyword_hash(args, &keyword_hash, 1)) {
- /* Warn the following:
- * def foo(k:1) p [k]; end
- * foo({k:42}) #=> 42
- */
- if (ec->cfp->iseq) {
- /* called from Ruby level */
- rb_warn_last_hash_to_keyword(calling, ci);
- }
- given_argc--;
- }
- else if (keyword_hash != Qnil && ec->cfp->iseq) {
- rb_warn_split_last_hash_to_keyword(calling, ci);
- }
+ else if (args_pop_keyword_hash(args, &keyword_hash, 1)) {
+ /* Warn the following:
+ * def foo(k:1) p [k]; end
+ * foo({k:42}) #=> 42
+ */
+ if (ec->cfp->iseq) {
+ /* called from Ruby level */
+ rb_warn_last_hash_to_keyword(calling, ci);
+ }
+ given_argc--;
+ }
+ else if (keyword_hash != Qnil && ec->cfp->iseq) {
+ rb_warn_split_last_hash_to_keyword(calling, ci);
+ }
+ }
+ else if (given_argc == min_argc && kw_flag) {
+ rb_warn_keyword_to_last_hash(calling, ci);
+ }
}
if (given_argc > max_argc && max_argc != UNLIMITED_ARGUMENTS) {