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

2 participants

@kachick

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
JRuby Team member

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

@kachick

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
JRuby Team member

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
JRuby Team member

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

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

@jrubyci jrubyci closed this in #815 Jun 21, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment