ruby-changes:59343
From: Yusuke <ko1@a...>
Date: Fri, 20 Dec 2019 19:45:27 +0900 (JST)
Subject: [ruby-changes:59343] f7aee58498 (master): vm_args.c: rephrase the warning message of keyword argument separation
https://git.ruby-lang.org/ruby.git/commit/?id=f7aee58498 From f7aee584987e24768670e96b1455ed1193f91ef2 Mon Sep 17 00:00:00 2001 From: Yusuke Endoh <mame@r...> Date: Fri, 20 Dec 2019 19:41:15 +0900 Subject: vm_args.c: rephrase the warning message of keyword argument separation (old) test.rb:4: warning: The last argument is used as the keyword parameter test.rb:1: warning: for `foo' defined here; maybe ** should be added to the call? (new) test.rb:4: warning: The last argument is used as keyword parameters; maybe ** should be added to the call test.rb:1: warning: The called method `foo' is defined here diff --git a/class.c b/class.c index 4129647..cceba6a 100644 --- a/class.c +++ b/class.c @@ -2051,7 +2051,7 @@ rb_scan_args_parse(int kw_flag, int argc, const VALUE *argv, const char *fmt, st https://github.com/ruby/ruby/blob/trunk/class.c#L2051 if (!keyword_given && !last_hash_keyword) { /* Warn if treating positional as keyword, as in Ruby 3, this will be an error */ - rb_warn("The last argument is used as the keyword parameter"); + rb_warn("The last argument is used as keyword parameters"); } argc--; } diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h index 8a5aacb..57b5075 100644 --- a/include/ruby/ruby.h +++ b/include/ruby/ruby.h @@ -2569,7 +2569,7 @@ rb_scan_args_set(int argc, const VALUE *argv, https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L2569 if (!keyword_given) { /* Warn if treating positional as keyword, as in Ruby 3, this will be an error */ - rb_warn("The last argument is used as the keyword parameter"); + rb_warn("The last argument is used as keyword parameters"); } argc--; } diff --git a/test/-ext-/funcall/test_passing_block.rb b/test/-ext-/funcall/test_passing_block.rb index c2d7639..dd67b7c 100644 --- a/test/-ext-/funcall/test_passing_block.rb +++ b/test/-ext-/funcall/test_passing_block.rb @@ -29,7 +29,7 @@ class TestFuncall < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/-ext-/funcall/test_passing_block.rb#L29 assert_equal([[{}], {}], Relay.with_funcall_passing_block_kw(2, {}, **{}, &block)) assert_equal([[], {a: 1}], Relay.with_funcall_passing_block_kw(3, a: 1, &block)) assert_equal([[{a: 1}], {}], Relay.with_funcall_passing_block_kw(3, {a: 1}, **{}, &block)) - assert_warn(/warning: The keyword argument is passed as the last hash parameter.*for method/m) do + assert_warn(/warning: The keyword argument is passed as the last hash parameter.*The called method is defined here/m) do assert_equal({}, Relay.with_funcall_passing_block_kw(3, **{}, &->(a){a})) end end @@ -53,7 +53,7 @@ class TestFuncall < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/-ext-/funcall/test_passing_block.rb#L53 assert_equal([[], {a: 1}], Relay.with_funcallv_public_kw(o, :foo, 3, a: 1)) assert_equal([[{a: 1}], {}], Relay.with_funcallv_public_kw(o, :foo, 3, {a: 1}, **{})) assert_raise(NoMethodError) { Relay.with_funcallv_public_kw(o, :bar, 3, {a: 1}, **{}) } - assert_warn(/warning: The keyword argument is passed as the last hash parameter.*for `baz'/m) do + assert_warn(/warning: The keyword argument is passed as the last hash parameter.*The called method `baz'/m) do assert_equal({}, Relay.with_funcallv_public_kw(o, :baz, 3, **{})) end end @@ -64,7 +64,7 @@ class TestFuncall < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/-ext-/funcall/test_passing_block.rb#L64 assert_equal([[], {a: 1}], Relay.with_yield_splat_kw(1, [{a: 1}], &block)) assert_equal([[1], {a: 1}], Relay.with_yield_splat_kw(1, [1, {a: 1}], &block)) assert_equal([[{}], {}], Relay.with_yield_splat_kw(2, [{}], **{}, &block)) - assert_warn(/warning: The last argument is used as the keyword parameter.*for method/m) do + assert_warn(/warning: The last argument is used as keyword parameters.*The called method is defined here/m) do assert_equal([[], {a: 1}], Relay.with_yield_splat_kw(3, [{a: 1}], &block)) end assert_equal([[{a: 1}], {}], Relay.with_yield_splat_kw(3, [{a: 1}], **{}, &block)) diff --git a/test/ruby/test_exception.rb b/test/ruby/test_exception.rb index 94b59da..b1f4681 100644 --- a/test/ruby/test_exception.rb +++ b/test/ruby/test_exception.rb @@ -1208,8 +1208,8 @@ $stderr = $stdout; raise "\x82\xa0"') do |outs, errs, status| https://github.com/ruby/ruby/blob/trunk/test/ruby/test_exception.rb#L1208 assert_raise(ArgumentError) {warn("test warning", uplevel: -1)} assert_in_out_err(["-e", "warn 'ok', uplevel: 1"], '', [], /warning:/) warning = capture_warning_warn {warn("test warning", {uplevel: 0})} - assert_equal("#{__FILE__}:#{__LINE__-1}: warning: The last argument is used as the keyword parameter\n", warning[0]) - assert_match(/warning: for method defined here|warning: test warning/, warning[1]) + assert_equal("#{__FILE__}:#{__LINE__-1}: warning: The last argument is used as keyword parameters; maybe ** should be added to the call\n", warning[0]) + assert_match(/warning: The called method (?:`.*' )?is defined here|warning: test warning/, warning[1]) warning = capture_warning_warn {warn("test warning", **{uplevel: 0})} assert_equal("#{__FILE__}:#{__LINE__-1}: warning: test warning\n", warning[0]) warning = capture_warning_warn {warn("test warning", {uplevel: 0}, **{})} diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index f3b0815..9a3a0f8 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -2284,7 +2284,7 @@ class TestIO < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io.rb#L2284 def o.to_open(**kw); kw; end assert_equal({:a=>1}, open(o, a: 1)) - w = /The last argument is used as the keyword parameter.*for `(to_)?open'/m + w = /The last argument is used as keyword parameters.*The called method `(to_)?open'/m redefined = nil w.singleton_class.define_method(:===) do |s| match = super(s) diff --git a/test/ruby/test_keyword.rb b/test/ruby/test_keyword.rb index 874b09b..3d5cb2d 100644 --- a/test/ruby/test_keyword.rb +++ b/test/ruby/test_keyword.rb @@ -24,7 +24,7 @@ class TestKeywordArguments < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L24 def test_f2 assert_equal([:xyz, "foo", 424242], f2(:xyz)) - assert_warn(/The keyword argument is passed as the last hash parameter.* for `f2'/m) do + assert_warn(/The keyword argument is passed as the last hash parameter.*The called method `f2'/m) do assert_equal([{"bar"=>42}, "foo", 424242], f2("bar"=>42)) end end @@ -224,10 +224,10 @@ class TestKeywordArguments < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L224 def c.m(args) args end - assert_warn(/The keyword argument is passed as the last hash parameter.* for `m'/m) do + assert_warn(/The keyword argument is passed as the last hash parameter.*The called method `m'/m) do assert_equal(kw, c.m(**{})) end - assert_warn(/The keyword argument is passed as the last hash parameter.* for `m'/m) do + assert_warn(/The keyword argument is passed as the last hash parameter.*The called method `m'/m) do assert_equal(kw, c.m(**kw)) end assert_equal(kw, c.m(kw, **kw)) @@ -248,11 +248,11 @@ class TestKeywordArguments < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L248 assert_equal(h2, c.m(**h2)) assert_equal(h3, c.m(**h3)) assert_equal(h3, c.m(a: 1, **h2)) - assert_warn(/The last argument is used as the keyword parameter.*for `m'/m) do + assert_warn(/The last argument is used as keyword parameters.*The called method `m'/m) do assert_equal(h, c.m(h)) end assert_raise(ArgumentError) { c.m(h2) } - assert_warn(/The last argument is split into positional and keyword parameters.*for `m'/m) do + assert_warn(/The last argument is split into positional and keyword parameters.*The called method `m'/m) do assert_raise(ArgumentError) { c.m(h3) } end @@ -260,25 +260,25 @@ class TestKeywordArguments < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L260 def c.m(arg, **args) [arg, args] end - assert_warn(/The keyword argument is passed as the last hash parameter.* for `m'/m) do + assert_warn(/The keyword argument is passed as the last hash parameter.*The called method `m'/m) do c.m(**{}) end - assert_warn(/The keyword argument is passed as the last hash parameter.* for `m'/m) do + assert_warn(/The keyword argument is passed as the last hash parameter.*The called method `m'/m) do c.m(**kw) end - assert_warn(/The keyword argument is passed as the last hash parameter.* for `m'/m) do + assert_warn(/The keyword argument is passed as the last hash parameter.*The called method `m'/m) do assert_equal([h, kw], c.m(**h)) end - assert_warn(/The keyword argument is passed as the last hash parameter.* for `m'/m) do + assert_warn(/The keyword argument is passed as the last hash parameter.*The called method `m'/m) do assert_equal([h, kw], c.m(a: 1)) end - assert_warn(/The keyword argument is passed as the last hash parameter.* for `m'/m) do + assert_warn(/The keyword argument is passed as the last hash parameter.*The called method `m'/m) do assert_equal([h2, kw], c.m(**h2)) end - assert_warn(/The keyword argument is passed as the last hash parameter.* for `m'/m) do + assert_warn(/The keyword argument is passed as the last hash parameter.*The called method `m'/m) do assert_equa (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/