1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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]
This commit is contained in:
Jeremy Evans 2020-01-21 16:14:10 -08:00
parent 90f5c3c1ea
commit 28d31ead34
Notes: git 2020-01-23 03:27:26 +09:00
2 changed files with 5 additions and 1 deletions

View file

@ -223,7 +223,7 @@ class PP < PrettyPrint
else
sep.call
end
yield(*v)
yield(*v, **{})
}
end

View file

@ -176,6 +176,10 @@ 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))
end
end
class PPDelegateTest < Test::Unit::TestCase