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

JRuby19mode behavior is different with CRuby. When Enumerator has mulltiple values for a block paramter. #264

Closed
kachick opened this issue Aug 20, 2012 · 5 comments
Labels
Milestone

Comments

@kachick
Copy link
Contributor

@kachick kachick commented Aug 20, 2012

Are below behaviors expected in JRuby?

$VERBOSE = true

def each_foo(&block)
  return to_enum(__callee__) unless block_given?

  yield :a, 1
  block.call :b, 2, '3rd-arg'
end

each_foo do |*args|
  p args
end

enum = each_foo
p enum.next
p enum.next

CRuby

ruby 1.9.3p194 (2012-04-20) [i386-mingw32]

[:a, 1]
[:b, 2, "3rd-arg"]
[:a, 1]
[:b, 2, "3rd-arg"]

JRuby

jruby 1.7.0.preview2 (1.9.3p203) 2012-08-07 4a6bb0a on Java HotSpot(TM) Client VM 1.6.0_29-b11 [Windows 7-x86]

jruby --1.8

[:a, 1]
[:b, 2, "3rd-arg"]
[:a, 1]
warning: multiple values for a block parameter (3 for 1)
[:b, 2, "3rd-arg"]

jruby --1.9

[:a, 1]
[:b, 2, "3rd-arg"]
:a
:b
@headius
Copy link
Member

@headius headius commented Aug 21, 2012

We should always match MRI for this sort of thing, so this is a valid bug.

@kachick
Copy link
Contributor Author

@kachick kachick commented Aug 25, 2012

Thanks for the reply!
And i have tried monkey-patching.

class Generator::Threaded::ProducerQueue

  remove_method :_run_enum

  def _run_enum(enum)
    _run { enum.each { |*args|self.yield(args) } }
  end

end

It looks done well.

@headius
Copy link
Member

@headius headius commented Aug 27, 2012

I attempted to make apply that monkey-patch but it appeared to break 1.8 mode test runs. I'm going to see if perhaps we need to split this logic between 1.8 and 1.9 modes, since they do handle block/proc arguments differently.

@headius
Copy link
Member

@headius headius commented Aug 28, 2012

Yeah, unfortunately the monkey-patch breaks even if I only apply it to 1.9 mode. This isn't the right fix I'm afraid :(

@kachick
Copy link
Contributor Author

@kachick kachick commented Aug 28, 2012

Thanks for the comment to monkey-patch.
I've understood it.

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

Successfully merging a pull request may close this issue.

2 participants