jruby/jruby — pull request #807 by dmarcotte (2013-06-17 00:08:46+00:00)
Title: Fix each_with_index argument handling

This fixes #744 and cleans up a couple of related things discovered while down that rabbit hole.

The block `RubyEnumerable` creates to handle `each_with_index` was incorrectly assigned a fixed arity of two. When the `each` we passed this block to is implemented with a `call` rather than a `yield`, this arity was enforced. This resulted in wrapping zero or one arguments in an array (which is what leads to #744) or, in the case of more than two arguments, lopping off the extra arguments.

This pull updates the `each_with_index` block to have `Arity.OPTIONAL`, and fixes the `EachWithIndex.call` logic around packaging up the arguments to handle all arities properly.

Also noticed that `RubyEnumerator$EachWithIndex` needed precisely the same logic around argument packaging, and refactored it to use the fixed `RubyEnumerable$EachWithIndex`. In particular, this fixes an issue where `RubyEnumerator$EachWithIndex` handled multiple arguments incorrectly (it always truncated down to the first arg).