Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix each_with_index argument handling #807

Merged
merged 1 commit into from Jun 17, 2013

Conversation

dmarcotte
Copy link
Contributor

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).

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 or, in the case of more than two arguments, lopping off the
extra arguments.

Update the each_with_index block to have Arity.OPTIONAL, and fix the
EachWithIndex.call logic around packaging up the arguments to handle
all arities properly.

`RubyEnumerator$EachWithIndex` also needs precisely the same logic
around argument packaging, so refactor it to use the fixed
`RubyEnumerable$EachWithIndex`
BanzaiMan added a commit that referenced this pull request Jun 17, 2013
Fix each_with_index argument handling
@BanzaiMan BanzaiMan merged commit 3ecf9ae into jruby:master Jun 17, 2013
@BanzaiMan
Copy link
Member

I verified the specs, though they weren't run by CI (See https://travis-ci.org/jruby/jruby/jobs/8144748). I fixed this with 215ebe2.

Thanks, @dmarcotte!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeError with Prime.each_with_index and mass assignment
2 participants