[前][次][番号順一覧][スレッド一覧]

ruby-changes:57674

From: Jeremy <ko1@a...>
Date: Mon, 9 Sep 2019 14:47:31 +0900 (JST)
Subject: [ruby-changes:57674] 61d90da25c (master): Fix invalid keyword argument separation warning for delegating calls

https://git.ruby-lang.org/ruby.git/commit/?id=61d90da25c

From 61d90da25c027f896ddc0e71c7b17c67d4b12a97 Mon Sep 17 00:00:00 2001
From: Jeremy Evans <code@j...>
Date: Sun, 8 Sep 2019 20:51:56 -0700
Subject: Fix invalid keyword argument separation warning for delegating calls

This removes an invalid keyword argument separation warning for
code such as:

```ruby
def foo(arg)
  arg
end
kw = {}
foo(*[1], **kw)
```

This warning was caused because the remove_empty_keyword_hash
was set based on a comparison with two variables, and in this
case, one of the variables was updated after the check and we
need to use the updated variable.

Simplify things by just inlining the comparison.

diff --git a/test/ruby/test_keyword.rb b/test/ruby/test_keyword.rb
index 5864ec9..5ddcfd8 100644
--- a/test/ruby/test_keyword.rb
+++ b/test/ruby/test_keyword.rb
@@ -215,6 +215,7 @@ class TestKeywordArguments < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L215
     assert_warn(/The keyword argument is passed as the last hash parameter.* for `m'/m) do
       assert_equal(kw, c.m(**kw))
     end
+    assert_equal(kw, c.m(kw, **kw))
     assert_equal(h, c.m(**h))
     assert_equal(h, c.m(a: 1))
     assert_equal(h2, c.m(**h2))
diff --git a/vm_args.c b/vm_args.c
index 7ffc756..e471095 100644
--- a/vm_args.c
+++ b/vm_args.c
@@ -654,7 +654,6 @@ setup_parameters_complex(rb_execution_context_t * const ec, const rb_iseq_t * co https://github.com/ruby/ruby/blob/trunk/vm_args.c#L654
     VALUE keyword_hash = Qnil;
     VALUE * const orig_sp = ec->cfp->sp;
     unsigned int i;
-    int remove_empty_keyword_hash = 1;
 
     vm_check_canary(ec, orig_sp);
     /*
@@ -704,10 +703,6 @@ setup_parameters_complex(rb_execution_context_t * const ec, const rb_iseq_t * co https://github.com/ruby/ruby/blob/trunk/vm_args.c#L703
 	args->kw_argv = NULL;
     }
 
-    if (given_argc == min_argc) {
-        remove_empty_keyword_hash = 0;
-    }
-
     if (ci->flag & VM_CALL_ARGS_SPLAT) {
 	args->rest = locals[--args->argc];
 	args->rest_index = 0;
@@ -715,7 +710,7 @@ setup_parameters_complex(rb_execution_context_t * const ec, const rb_iseq_t * co https://github.com/ruby/ruby/blob/trunk/vm_args.c#L710
         if (kw_flag & VM_CALL_KW_SPLAT) {
             int len = RARRAY_LENINT(args->rest);
             if (len > 0 && ignore_keyword_hash_p(RARRAY_AREF(args->rest, len - 1), iseq)) {
-                if (remove_empty_keyword_hash) {
+                if (given_argc != min_argc) {
                     arg_rest_dup(args);
                     rb_ary_pop(args->rest);
                     given_argc--;
@@ -730,7 +725,7 @@ setup_parameters_complex(rb_execution_context_t * const ec, const rb_iseq_t * co https://github.com/ruby/ruby/blob/trunk/vm_args.c#L725
     else {
         if (kw_flag & VM_CALL_KW_SPLAT) {
             if (ignore_keyword_hash_p(args->argv[args->argc-1], iseq)) {
-                if (remove_empty_keyword_hash) {
+                if (given_argc != min_argc) {
                     args->argc--;
                     given_argc--;
                     kw_flag &= ~VM_CALL_KW_SPLAT;
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]