Skip to content

JRuby starts executing Enumerator code too soon #4583

@janko

Description

@janko

Environment

$ jruby -v
jruby 9.1.8.0 (2.3.1) 2017-03-06 90fc7ab Java HotSpot(TM) 64-Bit Server VM 25.40-b25 on 1.8.0_40-b27 +jit [darwin-x86_64]
$ uname -a
Darwin Jankos-MacBook-Pro.local 16.4.0 Darwin Kernel Version 16.4.0: Thu Dec 22 22:53:21 PST 2016; root:xnu-3789.41.3~3/RELEASE_X86_64 x86_64

Expected Behavior

For the given code

enumerator = Enumerator.new do |yielder|
  yielder << nil
  puts "EXECUTED"
end

enumerator.next

MRI 2.4.1 doesn't output anything. I expected JRuby to behave the same, to pause and not to execute any code after yield, since we requested only the first element of the Enumerator.

Actual Behavior

However, JRuby outputs

EXECUTED

In other words, JRuby started executing the code after yield, even though we only asked for the first element.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions