ruby-changes:57592
From: Jeremy <ko1@a...>
Date: Fri, 6 Sep 2019 11:45:14 +0900 (JST)
Subject: [ruby-changes:57592] 1fffd33189 (master): Fix passing keywords without splats to sym procs, define_method, and method_missing
https://git.ruby-lang.org/ruby.git/commit/?id=1fffd33189 From 1fffd33189ddb4dfdefe2ada09ec884f89e305ce Mon Sep 17 00:00:00 2001 From: Jeremy Evans <code@j...> Date: Wed, 4 Sep 2019 15:47:53 -0700 Subject: Fix passing keywords without splats to sym procs, define_method, and method_missing diff --git a/test/ruby/test_keyword.rb b/test/ruby/test_keyword.rb index 91e53e1..9e32faa 100644 --- a/test/ruby/test_keyword.rb +++ b/test/ruby/test_keyword.rb @@ -179,7 +179,7 @@ class TestKeywordArguments < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L179 def test_lambda_kwsplat_call kw = {} - h = {'a'=>1} + h = {:a=>1} h2 = {'a'=>1} h3 = {'a'=>1, :a=>1} @@ -187,6 +187,7 @@ class TestKeywordArguments < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L187 assert_equal(true, f[**{}]) assert_equal(true, f[**kw]) assert_raise(ArgumentError) { f[**h] } + assert_raise(ArgumentError) { f[a: 1] } assert_raise(ArgumentError) { f[**h2] } assert_raise(ArgumentError) { f[**h3] } @@ -194,15 +195,19 @@ class TestKeywordArguments < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L195 assert_raise(ArgumentError) { f[**{}] } assert_raise(ArgumentError) { f[**kw] } assert_equal(h, f[**h]) + assert_equal(h, f[a: 1]) assert_equal(h2, f[**h2]) assert_equal(h3, f[**h3]) + assert_equal(h3, f[a: 1, **h2]) f = ->(**x) { x } assert_equal(kw, f[**{}]) assert_equal(kw, f[**kw]) assert_equal(h, f[**h]) + assert_equal(h, f[a: 1]) assert_equal(h2, f[**h2]) assert_equal(h3, f[**h3]) + assert_equal(h3, f[a: 1, **h2]) f = ->(a, **x) { [a,x] } assert_warn(/The keyword argument is passed as the last hash parameter.* for `\[\]'/m) do @@ -215,23 +220,31 @@ class TestKeywordArguments < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L220 assert_equal([h, {}], f[**h]) end assert_warn(/The keyword argument is passed as the last hash parameter.* for `\[\]'/m) do + assert_equal([h, {}], f[a: 1]) + end + 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 is passed as the last hash parameter.* for `\[\]'/m) do assert_equal([h3, {}], f[**h3]) end + assert_warn(/The keyword argument is passed as the last hash parameter.* for `\[\]'/m) do + assert_equal([h3, {}], f[a: 1, **h2]) + end f = ->(a=1, **x) { [a, x] } assert_equal([1, kw], f[**{}]) assert_equal([1, kw], f[**kw]) assert_equal([1, h], f[**h]) + assert_equal([1, h], f[a: 1]) assert_equal([1, h2], f[**h2]) assert_equal([1, h3], f[**h3]) + assert_equal([1, h3], f[a: 1, **h2]) end def test_cfunc_kwsplat_call kw = {} - h = {'a'=>1} + h = {:a=>1} h2 = {'a'=>1} h3 = {'a'=>1, :a=>1} @@ -250,8 +263,10 @@ class TestKeywordArguments < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L263 assert_equal([], c[**{}].args) assert_equal([], c[**kw].args) assert_equal([h], c[**h].args) + assert_equal([h], c[a: 1].args) assert_equal([h2], c[**h2].args) assert_equal([h3], c[**h3].args) + assert_equal([h3], c[a: 1, **h2].args) c = Class.new(sc) do def initialize; end @@ -259,8 +274,10 @@ class TestKeywordArguments < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L274 assert_nil(c[**{}].args) assert_nil(c[**kw].args) assert_raise(ArgumentError) { c[**h] } + assert_raise(ArgumentError) { c[a: 1] } assert_raise(ArgumentError) { c[**h2] } assert_raise(ArgumentError) { c[**h3] } + assert_raise(ArgumentError) { c[a: 1, **h2] } c = Class.new(sc) do def initialize(args) @@ -270,8 +287,10 @@ class TestKeywordArguments < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L287 assert_raise(ArgumentError) { c[**{}] } assert_raise(ArgumentError) { c[**kw] } assert_equal(h, c[**h].args) + assert_equal(h, c[a: 1].args) assert_equal(h2, c[**h2].args) assert_equal(h3, c[**h3].args) + assert_equal(h3, c[a: 1, **h2].args) c = Class.new(sc) do def initialize(**args) @@ -281,8 +300,10 @@ class TestKeywordArguments < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L300 assert_equal(kw, c[**{}].args) assert_equal(kw, c[**kw].args) assert_equal(h, c[**h].args) + assert_equal(h, c[a: 1].args) assert_equal(h2, c[**h2].args) assert_equal(h3, c[**h3].args) + assert_equal(h3, c[a: 1, **h2].args) c = Class.new(sc) do def initialize(arg, **args) @@ -292,8 +313,10 @@ class TestKeywordArguments < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L313 assert_raise(ArgumentError) { c[**{}] } assert_raise(ArgumentError) { c[**kw] } assert_equal([h, kw], c[**h].args) + assert_equal([h, kw], c[a: 1].args) assert_equal([h2, kw], c[**h2].args) assert_equal([h3, kw], c[**h3].args) + assert_equal([h3, kw], c[a: 1, **h2].args) c = Class.new(sc) do def initialize(arg=1, **args) @@ -303,13 +326,15 @@ class TestKeywordArguments < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L326 assert_equal([1, kw], c[**{}].args) assert_equal([1, kw], c[**kw].args) assert_equal([1, h], c[**h].args) + assert_equal([1, h], c[a: 1].args) assert_equal([1, h2], c[**h2].args) assert_equal([1, h3], c[**h3].args) + assert_equal([1, h3], c[a: 1, **h2].args) end def test_method_kwsplat_call kw = {} - h = {'a'=>1} + h = {:a=>1} h2 = {'a'=>1} h3 = {'a'=>1, :a=>1} @@ -320,16 +345,20 @@ class TestKeywordArguments < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L345 assert_equal([], c.method(:m)[**{}]) assert_equal([], c.method(:m)[**kw]) assert_equal([h], c.method(:m)[**h]) + assert_equal([h], c.method(:m)[a: 1]) assert_equal([h2], c.method(:m)[**h2]) assert_equal([h3], c.method(:m)[**h3]) + assert_equal([h3], c.method(:m)[a: 1, **h2]) c.singleton_class.remove_method(:m) def c.m; end assert_nil(c.method(:m)[**{}]) assert_nil(c.method(:m)[**kw]) assert_raise(ArgumentError) { c.method(:m)[**h] } + assert_raise(ArgumentError) { c.method(:m)[a: 1] } assert_raise(ArgumentError) { c.method(:m)[**h2] } assert_raise(ArgumentError) { c.method(:m)[**h3] } + assert_raise(ArgumentError) { c.method(:m)[a: 1, **h2] } c.singleton_class.remove_method(:m) def c.m(args) @@ -338,8 +367,10 @@ class TestKeywordArguments < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L367 assert_raise(ArgumentError) { c.method(:m)[**{}] } assert_raise(ArgumentError) { c.method(:m)[**kw] } assert_equal(h, c.method(:m)[**h]) + assert_equal(h, c.method(:m)[a: 1]) assert_equal(h2, c.method(:m)[**h2]) assert_equal(h3, c.method(:m)[**h3]) + assert_equal(h3, c.method(:m)[a: 1, **h2]) c.singleton_class.remove_method(:m) def c.m(**args) @@ -348,8 +379,10 @@ class TestKeywordArguments < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L379 assert_equal(kw, c.method(:m)[**{}]) assert_equal(kw, c.method(:m)[**kw]) assert_equal(h, c.method(:m)[**h]) + assert_equal(h, c.method(:m)[a: 1]) assert_equal(h2, c.method(:m)[**h2]) assert_equal(h3, c.method(:m)[**h3]) + assert_equal(h3, c.method(:m)[a: 1, **h2]) c.singleton_class.remove_method(:m) def c.m(arg, **args) @@ -358,8 +391,10 @@ class TestKeywordArguments < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L391 assert_raise(ArgumentError) { c.method(:m)[**{}] } assert_raise(ArgumentError) { c.method(:m)[**kw] } assert_equal([h, kw], c.method(:m)[**h]) + assert_equal([h, kw], c.method(:m)[a: 1]) assert_equal([h2, kw], c.method(:m)[**h2]) assert_equal([h3, kw], c.method(:m)[**h3]) + assert_equal([h3, kw], c.method(:m)[a: 1, **h2]) c.singleton_class.remove_method(:m) def c.m(arg=1, **args) @@ -368,13 +403,15 @@ class TestKeywordArguments < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L403 assert_equal([1, kw], c.method(:m)[**{}]) assert_equal([1, kw], c.method(:m)[**kw]) assert_equal([1, h], c.method(:m)[**h]) + assert_equal([1, h], c.method(:m)[a: 1]) assert_equal([1, h2], c.method(:m)[**h2]) assert_equal([1, h3], c.method(:m)[**h3]) + assert_equal([1, h3], c.method(:m)[a: 1, **h2]) end def test_send_kwsplat kw = {} - h = {'a'=>1} + h = {:a=>1} h2 = {'a'=>1} h3 = {'a'=>1, :a=>1} @@ -385,16 +422,20 @@ class TestKeywordArguments < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L422 assert_equal([], c.send(:m, **{})) assert_equal([], c.send(:m, **kw)) assert_equal([h], c.send(:m, **h)) + assert_equal([h], c.send(:m, a: 1)) assert_equal([h2], c.send(:m, **h2)) assert_equal([h3], c.send(:m, **h3)) + assert_equal([h3], c.send(:m, a: 1, **h2)) c.singleton_class.remove_method(:m) def c.m; end assert_nil(c.send(:m, **{})) assert_nil(c.send(:m, **kw)) assert_raise(ArgumentError) { c.send(:m, **h) } + assert_raise(ArgumentError) { c.send(:m, a: 1) } assert_raise(ArgumentError) { c.send(:m, **h2) } assert_raise(ArgumentError) { c.send(:m, **h3) } + assert_raise(ArgumentError) { c.send(:m, a: 1, **h2) } c.singleton_class.remove_method (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/