mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Split warning messages for tag-jump
This commit is contained in:
parent
d4eef04883
commit
431a99b556
3 changed files with 39 additions and 30 deletions
|
@ -22,7 +22,7 @@ class TestKeywordArguments < Test::Unit::TestCase
|
|||
|
||||
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
|
|||
|
||||
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
|
|||
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
|
|||
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
|
|||
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
|
|||
[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
|
|||
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
|
||||
|
|
|
@ -155,7 +155,7 @@ class TestSyntax < Test::Unit::TestCase
|
|||
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
|
||||
|
|
27
vm_args.c
27
vm_args.c
|
@ -585,13 +585,16 @@ static inline void
|
|||
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
|
|||
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_iseq_location(iseq);
|
||||
if (NIL_P(loc)) {
|
||||
rb_warn("The last argument for `%s' is split into positional and keyword parameters", rb_id2name(ci->mid));
|
||||
rb_warn("The last argument for `%"PRIsVALUE"' is split into positional and keyword parameters",
|
||||
name);
|
||||
}
|
||||
else {
|
||||
rb_warn("The last argument for `%s' (defined at %s:%d) is split into positional and keyword parameters",
|
||||
rb_id2name(ci->mid), RSTRING_PTR(RARRAY_AREF(loc, 0)), FIX2INT(RARRAY_AREF(loc, 1)));
|
||||
rb_warn("The last argument is split into positional and keyword parameters");
|
||||
rb_compile_warn(RSTRING_PTR(RARRAY_AREF(loc, 0)), FIX2INT(RARRAY_AREF(loc, 1)),
|
||||
"for `%"PRIsVALUE"' defined here", name);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -613,13 +619,16 @@ static inline void
|
|||
rb_warn_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_iseq_location(iseq);
|
||||
if (NIL_P(loc)) {
|
||||
rb_warn("The last argument for `%s' is used as the keyword parameter", rb_id2name(ci->mid));
|
||||
rb_warn("The last argument for `%"PRIsVALUE"' is used as the keyword parameter",
|
||||
name);
|
||||
}
|
||||
else {
|
||||
rb_warn("The last argument for `%s' (defined at %s:%d) is used as the keyword parameter",
|
||||
rb_id2name(ci->mid), RSTRING_PTR(RARRAY_AREF(loc, 0)), FIX2INT(RARRAY_AREF(loc, 1)));
|
||||
rb_warn("The last argument is used as the keyword parameter");
|
||||
rb_compile_warn(RSTRING_PTR(RARRAY_AREF(loc, 0)), FIX2INT(RARRAY_AREF(loc, 1)),
|
||||
"for `%"PRIsVALUE"' defined here", name);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue