ruby-changes:59776
From: Jeremy <ko1@a...>
Date: Thu, 23 Jan 2020 03:27:23 +0900 (JST)
Subject: [ruby-changes:59776] 28d31ead34 (master): Fix pp when passed a empty ruby2_keywords-flagged hash as array element
https://git.ruby-lang.org/ruby.git/commit/?id=28d31ead34 From 28d31ead34baff1c4abc0d7d902ef4bc1d576fb2 Mon Sep 17 00:00:00 2001 From: Jeremy Evans <code@j...> Date: Tue, 21 Jan 2020 16:14:10 -0800 Subject: Fix pp when passed a empty ruby2_keywords-flagged hash as array element This causes problems because the hash is passed to a block not accepting keywords. Because the hash is empty and keyword flagged, it is removed before calling the block. This doesn't cause an ArgumentError because it is a block and not a lambda. Just like any other block not passed required arguments, arguments not passed are set to nil. Issues like this are a strong reason not to have ruby2_keywords by default. Fixes [Bug #16519] diff --git a/lib/pp.rb b/lib/pp.rb index 81a9a16..dede0d1 100644 --- a/lib/pp.rb +++ b/lib/pp.rb @@ -223,7 +223,7 @@ class PP < PrettyPrint https://github.com/ruby/ruby/blob/trunk/lib/pp.rb#L223 else sep.call end - yield(*v) + yield(*v, **{}) } end diff --git a/test/test_pp.rb b/test/test_pp.rb index 3262417..026b2ac 100644 --- a/test/test_pp.rb +++ b/test/test_pp.rb @@ -176,6 +176,10 @@ class PPSingleLineTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/test_pp.rb#L176 assert_equal("{1=>1}", PP.singleline_pp({ 1 => 1}, ''.dup)) # [ruby-core:02699] assert_equal("[1#{', 1'*99}]", PP.singleline_pp([1]*100, ''.dup)) end + + def test_hash_in_array + assert_equal("[{}]", PP.singleline_pp([->(*a){a.last}.ruby2_keywords.call(**{})], ''.dup)) + end end class PPDelegateTest < Test::Unit::TestCase -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/