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
This commit is contained in:
parent
2b2030f265
commit
f7aee58498
2
class.c
2
class.c
@ -2051,7 +2051,7 @@ rb_scan_args_parse(int kw_flag, int argc, const VALUE *argv, const char *fmt, st
|
||||
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--;
|
||||
}
|
||||
|
@ -2569,7 +2569,7 @@ rb_scan_args_set(int argc, const VALUE *argv,
|
||||
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--;
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ class TestFuncall < Test::Unit::TestCase
|
||||
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
|
||||
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
|
||||
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))
|
||||
|
@ -1208,8 +1208,8 @@ $stderr = $stdout; raise "\x82\xa0"') do |outs, errs, status|
|
||||
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}, **{})}
|
||||
|
@ -2284,7 +2284,7 @@ class TestIO < Test::Unit::TestCase
|
||||
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)
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -293,7 +293,7 @@ class TestNumeric < Test::Unit::TestCase
|
||||
assert_raise(ArgumentError, bug9811) { 1.step(10, 1, by: 11).size }
|
||||
|
||||
|
||||
e = assert_warn(/The last argument is used as the keyword parameter/) {
|
||||
e = assert_warn(/The last argument is used as keyword parameters/) {
|
||||
1.step(10, {by: "1"})
|
||||
}
|
||||
assert_warn('') {
|
||||
|
@ -1485,27 +1485,27 @@ class TestProcKeywords < Test::Unit::TestCase
|
||||
g = ->(kw) { kw.merge(:a=>2) }
|
||||
|
||||
assert_equal(2, (f >> g).call(a: 3)[:a])
|
||||
assert_warn(/The last argument is used as the keyword parameter.*for method/m) do
|
||||
assert_warn(/The last argument is used as keyword parameters.*The called method is defined here/m) do
|
||||
assert_equal(1, (f << g).call(a: 3)[:a])
|
||||
end
|
||||
assert_equal(2, (f >> g).call(a: 3)[:a])
|
||||
assert_warn(/The last argument is used as the keyword parameter.*for method/m) do
|
||||
assert_warn(/The last argument is used as keyword parameters.*The called method is defined here/m) do
|
||||
assert_equal(1, (f << g).call({a: 3})[:a])
|
||||
end
|
||||
assert_warn(/The last argument is used as the keyword parameter.*for method/m) do
|
||||
assert_warn(/The last argument is used as keyword parameters.*The called method is defined here/m) do
|
||||
assert_equal(2, (f >> g).call({a: 3})[:a])
|
||||
end
|
||||
assert_equal(2, (g << f).call(a: 3)[:a])
|
||||
assert_warn(/The last argument is used as the keyword parameter.*for method/m) do
|
||||
assert_warn(/The last argument is used as keyword parameters.*The called method is defined here/m) do
|
||||
assert_equal(1, (g >> f).call(a: 3)[:a])
|
||||
end
|
||||
assert_warn(/The last argument is used as the keyword parameter.*for method/m) do
|
||||
assert_warn(/The last argument is used as keyword parameters.*The called method is defined here/m) do
|
||||
assert_equal(2, (g << f).call({a: 3})[:a])
|
||||
end
|
||||
assert_warn(/The last argument is used as the keyword parameter.*for method/m) do
|
||||
assert_warn(/The last argument is used as keyword parameters.*The called method is defined here/m) do
|
||||
assert_equal(1, (g >> f).call({a: 3})[:a])
|
||||
end
|
||||
assert_warn(/The keyword argument is passed as the last hash parameter.*The last argument is used as the keyword parameter.*for method/m) do
|
||||
assert_warn(/The keyword argument is passed as the last hash parameter.*The last argument is used as keyword parameters.*The called method is defined here/m) do
|
||||
assert_equal(1, (f << g).call(**{})[:a])
|
||||
end
|
||||
assert_equal(2, (f >> g).call(**{})[:a])
|
||||
@ -1515,27 +1515,27 @@ class TestProcKeywords < Test::Unit::TestCase
|
||||
f = ->(**kw) { kw.merge(:a=>1) }.method(:call)
|
||||
g = ->(kw) { kw.merge(:a=>2) }.method(:call)
|
||||
|
||||
assert_warn(/The last argument is used as the keyword parameter.*for method/m) do
|
||||
assert_warn(/The last argument is used as keyword parameters.*The called method is defined here/m) do
|
||||
assert_equal(1, (f << g).call(a: 3)[:a])
|
||||
end
|
||||
assert_equal(2, (f >> g).call(a: 3)[:a])
|
||||
assert_warn(/The last argument is used as the keyword parameter.*for method/m) do
|
||||
assert_warn(/The last argument is used as keyword parameters.*The called method is defined here/m) do
|
||||
assert_equal(1, (f << g).call({a: 3})[:a])
|
||||
end
|
||||
assert_warn(/The last argument is used as the keyword parameter.*for method/m) do
|
||||
assert_warn(/The last argument is used as keyword parameters.*The called method is defined here/m) do
|
||||
assert_equal(2, (f >> g).call({a: 3})[:a])
|
||||
end
|
||||
assert_equal(2, (g << f).call(a: 3)[:a])
|
||||
assert_warn(/The last argument is used as the keyword parameter.*for method/m) do
|
||||
assert_warn(/The last argument is used as keyword parameters.*The called method is defined here/m) do
|
||||
assert_equal(1, (g >> f).call(a: 3)[:a])
|
||||
end
|
||||
assert_warn(/The last argument is used as the keyword parameter.*for method/m) do
|
||||
assert_warn(/The last argument is used as keyword parameters.*The called method is defined here/m) do
|
||||
assert_equal(2, (g << f).call({a: 3})[:a])
|
||||
end
|
||||
assert_warn(/The last argument is used as the keyword parameter.*for method/m) do
|
||||
assert_warn(/The last argument is used as keyword parameters.*The called method is defined here/m) do
|
||||
assert_equal(1, (g >> f).call({a: 3})[:a])
|
||||
end
|
||||
assert_warn(/The keyword argument is passed as the last hash parameter.*The last argument is used as the keyword parameter.*for method/m) do
|
||||
assert_warn(/The keyword argument is passed as the last hash parameter.*The last argument is used as keyword parameters.*The called method is defined here/m) do
|
||||
assert_equal(1, (f << g).call(**{})[:a])
|
||||
end
|
||||
assert_equal(2, (f >> g).call(**{})[:a])
|
||||
@ -1549,27 +1549,27 @@ class TestProcKeywords < Test::Unit::TestCase
|
||||
def g.<<(f) to_proc << f end
|
||||
def g.>>(f) to_proc >> f end
|
||||
|
||||
assert_warn(/The last argument is used as the keyword parameter.*for method/m) do
|
||||
assert_warn(/The last argument is used as keyword parameters.*The called method is defined here/m) do
|
||||
assert_equal(1, (f << g).call(a: 3)[:a])
|
||||
end
|
||||
assert_equal(2, (f >> g).call(a: 3)[:a])
|
||||
assert_warn(/The last argument is used as the keyword parameter.*for method/m) do
|
||||
assert_warn(/The last argument is used as keyword parameters.*The called method is defined here/m) do
|
||||
assert_equal(1, (f << g).call({a: 3})[:a])
|
||||
end
|
||||
assert_warn(/The last argument is used as the keyword parameter.*for method/m) do
|
||||
assert_warn(/The last argument is used as keyword parameters.*The called method is defined here/m) do
|
||||
assert_equal(2, (f >> g).call({a: 3})[:a])
|
||||
end
|
||||
assert_equal(2, (g << f).call(a: 3)[:a])
|
||||
assert_warn(/The last argument is used as the keyword parameter.*for method/m) do
|
||||
assert_warn(/The last argument is used as keyword parameters.*The called method is defined here/m) do
|
||||
assert_equal(1, (g >> f).call(a: 3)[:a])
|
||||
end
|
||||
assert_warn(/The last argument is used as the keyword parameter.*for method/m) do
|
||||
assert_warn(/The last argument is used as keyword parameters.*The called method is defined here/m) do
|
||||
assert_equal(2, (g << f).call({a: 3})[:a])
|
||||
end
|
||||
assert_warn(/The last argument is used as the keyword parameter.*for method/m) do
|
||||
assert_warn(/The last argument is used as keyword parameters.*The called method is defined here/m) do
|
||||
assert_equal(1, (g >> f).call({a: 3})[:a])
|
||||
end
|
||||
assert_warn(/The keyword argument is passed as the last hash parameter.*for `call'/m) do
|
||||
assert_warn(/The keyword argument is passed as the last hash parameter.*The called method `call'/m) do
|
||||
assert_equal(1, (f << g).call(**{})[:a])
|
||||
end
|
||||
assert_equal(2, (f >> g).call(**{})[:a])
|
||||
@ -1582,27 +1582,27 @@ class TestProcKeywords < Test::Unit::TestCase
|
||||
def g.>>(f) to_proc >> f end
|
||||
|
||||
assert_equal(1, (f << g).call(a: 3)[:a])
|
||||
assert_warn(/The last argument is used as the keyword parameter.*for `call'/m) do
|
||||
assert_warn(/The last argument is used as keyword parameters.*The called method `call'/m) do
|
||||
assert_equal(2, (f >> g).call(a: 3)[:a])
|
||||
end
|
||||
assert_warn(/The last argument is used as the keyword parameter.*for `call'/m) do
|
||||
assert_warn(/The last argument is used as keyword parameters.*The called method `call'/m) do
|
||||
assert_equal(1, (f << g).call({a: 3})[:a])
|
||||
end
|
||||
assert_warn(/The last argument is used as the keyword parameter.*for `call'/m) do
|
||||
assert_warn(/The last argument is used as keyword parameters.*The called method `call'/m) do
|
||||
assert_equal(2, (f >> g).call({a: 3})[:a])
|
||||
end
|
||||
assert_warn(/The last argument is used as the keyword parameter.*for `call'/m) do
|
||||
assert_warn(/The last argument is used as keyword parameters.*The called method `call'/m) do
|
||||
assert_equal(2, (g << f).call(a: 3)[:a])
|
||||
end
|
||||
assert_equal(1, (g >> f).call(a: 3)[:a])
|
||||
assert_warn(/The last argument is used as the keyword parameter.*for `call'/m) do
|
||||
assert_warn(/The last argument is used as keyword parameters.*The called method `call'/m) do
|
||||
assert_equal(2, (g << f).call({a: 3})[:a])
|
||||
end
|
||||
assert_warn(/The last argument is used as the keyword parameter.*for `call'/m) do
|
||||
assert_warn(/The last argument is used as keyword parameters.*The called method `call'/m) do
|
||||
assert_equal(1, (g >> f).call({a: 3})[:a])
|
||||
end
|
||||
assert_equal(1, (f << g).call(**{})[:a])
|
||||
assert_warn(/The keyword argument is passed as the last hash parameter.*The last argument is used as the keyword parameter.*for `call'/m) do
|
||||
assert_warn(/The keyword argument is passed as the last hash parameter.*The last argument is used as keyword parameters.*The called method `call'/m) do
|
||||
assert_equal(2, (f >> g).call(**{})[:a])
|
||||
end
|
||||
end
|
||||
|
@ -115,7 +115,7 @@ module TestStruct
|
||||
assert_equal "#{@Struct}::KeywordInitTrue(keyword_init: true)", @Struct::KeywordInitTrue.inspect
|
||||
# eval is needed to prevent the warning duplication filter
|
||||
k = eval("Class.new(@Struct::KeywordInitFalse) {def initialize(**) end}")
|
||||
assert_warn(/The last argument is used as the keyword parameter/) {k.new(a: 1, b: 2)}
|
||||
assert_warn(/The last argument is used as keyword parameters/) {k.new(a: 1, b: 2)}
|
||||
k = Class.new(@Struct::KeywordInitTrue) {def initialize(**) end}
|
||||
assert_warn('') {k.new(a: 1, b: 2)}
|
||||
|
||||
|
@ -182,7 +182,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 is split into positional and keyword parameters.* for `kw'/m) do
|
||||
assert_warn(/The last argument is split into positional and keyword parameters.*The called method `kw'/m) do
|
||||
assert_raise(ArgumentError) {o.kw(**h)}
|
||||
end
|
||||
end
|
||||
@ -1523,7 +1523,7 @@ eom
|
||||
assert_warning('') {
|
||||
assert_equal([[1, 2, 3], {k1: 4, k2: 5}], obj.foo(1, 2, 3, k1: 4, k2: 5))
|
||||
}
|
||||
warning = "warning: The last argument is used as the keyword parameter"
|
||||
warning = "warning: The last argument is used as keyword parameters"
|
||||
assert_warning(/\A\z|:(?!#{__LINE__+1})\d+: #{warning}/o) {
|
||||
assert_equal([[], {}], obj.foo({}) {|*x| x})
|
||||
}
|
||||
|
@ -190,7 +190,7 @@ class TestDelegateClass < Test::Unit::TestCase
|
||||
assert_equal([], d.bar)
|
||||
assert_equal([[], {:a=>1}], d.foo(:a=>1))
|
||||
assert_equal([{:a=>1}], d.bar(:a=>1))
|
||||
assert_warn(/The last argument is used as the keyword parameter.* for `foo'/m) do
|
||||
assert_warn(/The last argument is used as keyword parameters.*The called method `foo'/m) do
|
||||
assert_equal([[], {:a=>1}], d.foo({:a=>1}))
|
||||
end
|
||||
assert_equal([{:a=>1}], d.bar({:a=>1}))
|
||||
|
16
vm_args.c
16
vm_args.c
@ -658,11 +658,11 @@ rb_warn_keyword_to_last_hash(rb_execution_context_t * const ec, struct rb_callin
|
||||
rb_warn("The keyword argument is passed as the last hash parameter");
|
||||
if (name) {
|
||||
rb_compile_warn(RSTRING_PTR(RARRAY_AREF(loc, 0)), FIX2INT(RARRAY_AREF(loc, 1)),
|
||||
"for `%"PRIsVALUE"' defined here", name);
|
||||
"The called method `%"PRIsVALUE"' is defined here", name);
|
||||
}
|
||||
else {
|
||||
rb_compile_warn(RSTRING_PTR(RARRAY_AREF(loc, 0)), FIX2INT(RARRAY_AREF(loc, 1)),
|
||||
"for method defined here");
|
||||
"The called method is defined here");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -683,11 +683,11 @@ rb_warn_split_last_hash_to_keyword(rb_execution_context_t * const ec, struct rb_
|
||||
rb_warn("The last argument is split into positional and keyword parameters");
|
||||
if (calling->recv != Qundef) {
|
||||
rb_compile_warn(RSTRING_PTR(RARRAY_AREF(loc, 0)), FIX2INT(RARRAY_AREF(loc, 1)),
|
||||
"for `%"PRIsVALUE"' defined here", name);
|
||||
"The called method `%"PRIsVALUE"' is defined here", name);
|
||||
}
|
||||
else {
|
||||
rb_compile_warn(RSTRING_PTR(RARRAY_AREF(loc, 0)), FIX2INT(RARRAY_AREF(loc, 1)),
|
||||
"for method defined here");
|
||||
"The called method is defined here");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -701,18 +701,18 @@ rb_warn_last_hash_to_keyword(rb_execution_context_t * const ec, struct rb_callin
|
||||
name = rb_id2str(ci->mid);
|
||||
loc = rb_iseq_location(iseq);
|
||||
if (NIL_P(loc)) {
|
||||
rb_warn("The last argument for `%"PRIsVALUE"' is used as the keyword parameter; maybe ** should be added to the call?",
|
||||
rb_warn("The last argument for `%"PRIsVALUE"' is used as keyword parameters; maybe ** should be added to the call",
|
||||
name);
|
||||
}
|
||||
else {
|
||||
rb_warn("The last argument is used as the keyword parameter");
|
||||
rb_warn("The last argument is used as keyword parameters; maybe ** should be added to the call");
|
||||
if (calling->recv != Qundef) {
|
||||
rb_compile_warn(RSTRING_PTR(RARRAY_AREF(loc, 0)), FIX2INT(RARRAY_AREF(loc, 1)),
|
||||
"for `%"PRIsVALUE"' defined here; maybe ** should be added to the call?", name);
|
||||
"The called method `%"PRIsVALUE"' is defined here", name);
|
||||
}
|
||||
else {
|
||||
rb_compile_warn(RSTRING_PTR(RARRAY_AREF(loc, 0)), FIX2INT(RARRAY_AREF(loc, 1)),
|
||||
"for method defined here; maybe ** should be added to the call?");
|
||||
"The called method is defined here");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user