ruby-changes:58020
From: Nobuyoshi <ko1@a...>
Date: Mon, 30 Sep 2019 01:19:10 +0900 (JST)
Subject: [ruby-changes:58020] 59648af296 (master): Suppress keyword argument warning from #step
https://git.ruby-lang.org/ruby.git/commit/?id=59648af296 From 59648af296ab15a2e34ebce62a7cc14deb889e7b Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Mon, 30 Sep 2019 01:08:32 +0900 Subject: Suppress keyword argument warning from #step * numeric.c (num_step): pass the extracted argument from keyword argument, not the last argument itself which should have been warned already. diff --git a/numeric.c b/numeric.c index 5bf87bd..c1655c0 100644 --- a/numeric.c +++ b/numeric.c @@ -2768,7 +2768,7 @@ num_step(int argc, VALUE *argv, VALUE from) https://github.com/ruby/ruby/blob/trunk/numeric.c#L2768 num_step_size, from, to, step, FALSE); } - RETURN_SIZED_ENUMERATOR(from, argc, argv, num_step_size); + return SIZED_ENUMERATOR(from, 2, ((VALUE [2]){to, step}), num_step_size); } desc = num_step_scan_args(argc, argv, &to, &step, TRUE, FALSE); diff --git a/test/ruby/test_numeric.rb b/test/ruby/test_numeric.rb index f87abbb..797fd20 100644 --- a/test/ruby/test_numeric.rb +++ b/test/ruby/test_numeric.rb @@ -292,6 +292,14 @@ class TestNumeric < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_numeric.rb#L292 assert_raise(ArgumentError, bug9811) { 1.step(10, 1, by: 11) {} } assert_raise(ArgumentError, bug9811) { 1.step(10, 1, by: 11).size } + + e = assert_warn(/The last argument is used as the keyword parameter/) { + 1.step(10, {by: "1"}) + } + assert_warn('') { + assert_raise(ArgumentError) {e.size} + } + assert_equal(bignum*2+1, (-bignum).step(bignum, 1).size) assert_equal(bignum*2, (-bignum).step(bignum-1, 1).size) -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/