ruby-changes:57440
From: Nobuyoshi <ko1@a...>
Date: Sun, 1 Sep 2019 01:56:25 +0900 (JST)
Subject: [ruby-changes:57440] Nobuyoshi Nakada: 431a99b556 (master): Split warning messages for tag-jump
https://git.ruby-lang.org/ruby.git/commit/?id=431a99b556 From 431a99b5569e90dd76677be273ad81640ce7e757 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Sun, 1 Sep 2019 01:44:36 +0900 Subject: Split warning messages for tag-jump diff --git a/test/ruby/test_keyword.rb b/test/ruby/test_keyword.rb index 000f557..b27b5dc 100644 --- a/test/ruby/test_keyword.rb +++ b/test/ruby/test_keyword.rb @@ -22,7 +22,7 @@ class TestKeywordArguments < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L22 def test_f2 assert_equal([:xyz, "foo", 424242], f2(:xyz)) - assert_warn(/The keyword argument for `f2' .* is passed as the last hash parameter/) do + assert_warn(/The keyword argument is passed as the last hash parameter.* for `f2'/m) do assert_equal([{"bar"=>42}, "foo", 424242], f2("bar"=>42)) end end @@ -206,16 +206,16 @@ class TestKeywordArguments < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L206 f = ->(a, **x) { [a,x] } assert_raise(ArgumentError) { f[**{}] } - assert_warn(/The keyword argument for `\[\]' .* is passed as the last hash parameter/) do + assert_warn(/The keyword argument is passed as the last hash parameter.* for `\[\]'/m) do assert_equal([{}, {}], f[**kw]) end - assert_warn(/The keyword argument for `\[\]' .* is passed as the last hash parameter/) do + assert_warn(/The keyword argument is passed as the last hash parameter.* for `\[\]'/m) do assert_equal([h, {}], f[**h]) end - assert_warn(/The keyword argument for `\[\]' .* is passed as the last hash parameter/) do + assert_warn(/The keyword argument is passed as the last hash parameter.* for `\[\]'/m) do assert_equal([h2, {}], f[**h2]) end - assert_warn(/The keyword argument for `\[\]' .* is passed as the last hash parameter/) do + assert_warn(/The keyword argument is passed as the last hash parameter.* for `\[\]'/m) do assert_equal([h3, {}], f[**h3]) end @@ -353,22 +353,22 @@ class TestKeywordArguments < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L353 bug7665 = '[ruby-core:51278]' bug8463 = '[ruby-core:55203] [Bug #8463]' expect = [*%w[foo bar], {zzz: 42}] - assert_warn(/The last argument for `rest_keyrest' .* is used as the keyword parameter/) do + assert_warn(/The last argument is used as the keyword parameter.* for `rest_keyrest'/m) do assert_equal(expect, rest_keyrest(*expect), bug7665) end pr = proc {|*args, **opt| next *args, opt} - assert_warn(/The last argument for `call' .* is used as the keyword parameter/) do + assert_warn(/The last argument is used as the keyword parameter.* for `call'/m) do assert_equal(expect, pr.call(*expect), bug7665) end - assert_warn(/The last argument for `call' .* is used as the keyword parameter/) do + assert_warn(/The last argument is used as the keyword parameter.* for `call'/m) do assert_equal(expect, pr.call(expect), bug8463) end pr = proc {|a, *b, **opt| next a, *b, opt} - assert_warn(/The last argument for `call' .* is used as the keyword parameter/) do + assert_warn(/The last argument is used as the keyword parameter.* for `call'/m) do assert_equal(expect, pr.call(expect), bug8463) end pr = proc {|a, **opt| next a, opt} - assert_warn(/The last argument for `call' .* is used as the keyword parameter/) do + assert_warn(/The last argument is used as the keyword parameter.* for `call'/m) do assert_equal(expect.values_at(0, -1), pr.call(expect), bug8463) end end @@ -386,13 +386,13 @@ class TestKeywordArguments < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L386 end def test_keyword_split - assert_warn(/The keyword argument for `req_plus_keyword' .* is passed as the last hash parameter/) do + assert_warn(/The keyword argument is passed as the last hash parameter.* for `req_plus_keyword'/m) do assert_equal([{:a=>1}, {}], req_plus_keyword(:a=>1)) end - assert_warn(/The keyword argument for `req_plus_keyword' .* is passed as the last hash parameter/) do + assert_warn(/The keyword argument is passed as the last hash parameter.* for `req_plus_keyword'/m) do assert_equal([{"a"=>1}, {}], req_plus_keyword("a"=>1)) end - assert_warn(/The keyword argument for `req_plus_keyword' .* is passed as the last hash parameter/) do + assert_warn(/The keyword argument is passed as the last hash parameter.* for `req_plus_keyword'/m) do assert_equal([{"a"=>1, :a=>1}, {}], req_plus_keyword("a"=>1, :a=>1)) end assert_equal([{:a=>1}, {}], req_plus_keyword({:a=>1})) @@ -402,22 +402,22 @@ class TestKeywordArguments < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L402 assert_equal([1, {:a=>1}], opt_plus_keyword(:a=>1)) assert_equal([1, {"a"=>1}], opt_plus_keyword("a"=>1)) assert_equal([1, {"a"=>1, :a=>1}], opt_plus_keyword("a"=>1, :a=>1)) - assert_warn(/The last argument for `opt_plus_keyword' .* is used as the keyword parameter/) do + assert_warn(/The last argument is used as the keyword parameter.* for `opt_plus_keyword'/m) do assert_equal([1, {:a=>1}], opt_plus_keyword({:a=>1})) end assert_equal([{"a"=>1}, {}], opt_plus_keyword({"a"=>1})) - assert_warn(/The last argument for `opt_plus_keyword' .* is split into positional and keyword parameters/) do + assert_warn(/The last argument is split into positional and keyword parameters.* for `opt_plus_keyword'/m) do assert_equal([{"a"=>1}, {:a=>1}], opt_plus_keyword({"a"=>1, :a=>1})) end assert_equal([[], {:a=>1}], splat_plus_keyword(:a=>1)) assert_equal([[], {"a"=>1}], splat_plus_keyword("a"=>1)) assert_equal([[], {"a"=>1, :a=>1}], splat_plus_keyword("a"=>1, :a=>1)) - assert_warn(/The last argument for `splat_plus_keyword' .* is used as the keyword parameter/) do + assert_warn(/The last argument is used as the keyword parameter.* for `splat_plus_keyword'/m) do assert_equal([[], {:a=>1}], splat_plus_keyword({:a=>1})) end assert_equal([[{"a"=>1}], {}], splat_plus_keyword({"a"=>1})) - assert_warn(/The last argument for `splat_plus_keyword' .* is split into positional and keyword parameters/) do + assert_warn(/The last argument is split into positional and keyword parameters.* for `splat_plus_keyword'/m) do assert_equal([[{"a"=>1}], {:a=>1}], splat_plus_keyword({"a"=>1, :a=>1})) end end @@ -604,7 +604,7 @@ class TestKeywordArguments < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L604 [a, b, c, d, e, f, g] end end - assert_warn(/The keyword argument for `foo' .* is passed as the last hash parameter/) do + assert_warn(/The keyword argument is passed as the last hash parameter.* for `foo'/m) do assert_equal([1, 2, 1, [], {:f=>5}, 2, {}], a.new.foo(1, 2, f:5), bug8993) end end @@ -639,10 +639,10 @@ class TestKeywordArguments < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L639 o = Object.new def o.to_hash() { k: 9 } end assert_equal([1, 42, [], o, :key, {}, nil], f9(1, o)) - assert_warn(/The last argument for `m1' .* is used as the keyword parameter/) do + assert_warn(/The last argument is used as the keyword parameter.* for `m1'/m) do assert_equal([1, 9], m1(1, o) {|a, k: 0| break [a, k]}, bug10016) end - assert_warn(/The last argument for `m1' .* is used as the keyword parameter/) do + assert_warn(/The last argument is used as the keyword parameter.* for `m1'/m) do assert_equal([1, 9], m1(1, o, &->(a, k: 0) {break [a, k]}), bug10016) end end diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index 85ff68e..b98a233 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -155,7 +155,7 @@ class TestSyntax < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L155 h = {k3: 31} assert_raise(ArgumentError) {o.kw(**h)} h = {"k1"=>11, k2: 12} - assert_warn(/The last argument for `kw' .* is split into positional and keyword parameters/) do + assert_warn(/The last argument is split into positional and keyword parameters.* for `kw'/m) do assert_raise(ArgumentError) {o.kw(**h)} end end diff --git a/vm_args.c b/vm_args.c index ab9ff58..ef3d9e2 100644 --- a/vm_args.c +++ b/vm_args.c @@ -585,13 +585,16 @@ static inline void https://github.com/ruby/ruby/blob/trunk/vm_args.c#L585 rb_warn_keyword_to_last_hash(struct rb_calling_info *calling, const struct rb_call_info *ci, const rb_iseq_t * const iseq) { if (calling->recv == Qundef) return; + VALUE name = rb_id2str(ci->mid); VALUE loc = rb_iseq_location(iseq); if (NIL_P(loc)) { - rb_warn("The keyword argument for `%s' is passed as the last hash parameter", rb_id2name(ci->mid)); + rb_warn("The keyword argument for `%"PRIsVALUE"' is passed as the last hash parameter", + name); } else { - rb_warn("The keyword argument for `%s' (defined at %s:%d) is passed as the last hash parameter", - rb_id2name(ci->mid), RSTRING_PTR(RARRAY_AREF(loc, 0)), FIX2INT(RARRAY_AREF(loc, 1))); + rb_warn("The keyword argument is passed as the last hash parameter"); + rb_compile_warn(RSTRING_PTR(RARRAY_AREF(loc, 0)), FIX2INT(RARRAY_AREF(loc, 1)), + "for `%"PRIsVALUE"' defined here", name); } } @@ -599,13 +602,16 @@ static inline void https://github.com/ruby/ruby/blob/trunk/vm_args.c#L602 rb_warn_split_last_hash_to_keyword(struct rb_calling_info *calling, const struct rb_call_info *ci, const rb_iseq_t * const iseq) { if (calling->recv == Qundef) return; + VALUE name = rb_id2str(ci->mid); VALUE loc = rb_i (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/