From bb93659fefd7f4557129043742771a33bd30c255 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Tue, 31 Mar 2020 00:10:57 -0700 Subject: Fix pp when passed a empty ruby2_keywords-flagged hash as array element (#2966) 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] This backports 28d31ead34baff1c4abc0d7d902ef4bc1d576fb2 and 0ea759eac9234afc47e8fb1bcacfe9ee12c8ffb6, but needed to be modified for 2.7 as 2.7 will perform empty keyword to positional hash conversion for required arguments, which will happen if "v" in the seplist method is empty when yielded. Co-authored-by: NARUSE, Yui --- test/test_pp.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'test') diff --git a/test/test_pp.rb b/test/test_pp.rb index 3262417fba..cd16af6394 100644 --- a/test/test_pp.rb +++ b/test/test_pp.rb @@ -176,6 +176,11 @@ class PPSingleLineTest < Test::Unit::TestCase 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)) + assert_equal("[{}]", PP.singleline_pp([Hash.ruby2_keywords_hash({})], ''.dup)) + end end class PPDelegateTest < Test::Unit::TestCase -- cgit v1.2.3