summaryrefslogtreecommitdiff
path: root/test/ruby/test_keyword.rb
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2020-02-24 13:19:37 -0800
committerNARUSE, Yui <naruse@airemix.jp>2020-03-15 19:35:24 +0900
commite70d52b0c377f8b2ed04311710c0ca9f4ebabd90 (patch)
treeb02a277cc2dfeddfbd72ee06e70bdd24f897f1aa /test/ruby/test_keyword.rb
parentb3fabedc7043593812c9ad507b4648a55d74df99 (diff)
Make ruby2_keywords methods correctly handle **{} optimization
Previously, this code: ruby2_keywords def foo(*a) a.last end foo(**{}) Returned an empty frozen hash. However, the final hash should not be frozen in this case, as it wouldn't be if foo accepted a keyword splat. Use a new unfrozen empty hash instead of reusing the frozen empty hash in this case. Fixes [Bug #16642]
Diffstat (limited to 'test/ruby/test_keyword.rb')
-rw-r--r--test/ruby/test_keyword.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/test/ruby/test_keyword.rb b/test/ruby/test_keyword.rb
index bbf3953c17..a0459553ac 100644
--- a/test/ruby/test_keyword.rb
+++ b/test/ruby/test_keyword.rb
@@ -5051,4 +5051,18 @@ class TestKeywordArgumentsSymProcRefinements < Test::Unit::TestCase
mock.new.foo
end
end
+
+ def test_ruby2_keywords_hash_empty_kw_splat
+ def self.foo(*a) a.last end
+ singleton_class.send(:ruby2_keywords, :foo)
+ bug16642 = '[ruby-core:97203] [Bug #16642]'
+
+ res = foo(**{})
+ assert_equal({}, res, bug16642)
+ assert_equal(false, res.frozen?, bug16642)
+
+ res = foo(*[], **{})
+ assert_equal({}, res, bug16642)
+ assert_equal(false, res.frozen?, bug16642)
+ end
end