Compare the following scenarios (they are the same, but the outcome is different):
First I'll do it on ruby (cruby)
~> irb
irb(main):001:0> begin
irb(main):002:1* begin
irb(main):003:2* puts 1
irb(main):004:2> next
irb(main):005:2> end
irb(main):006:1> puts 2
irb(main):007:1> end
SyntaxError: (irb):4: Can't escape from eval with next
Now same thing on jruby:
~> jirb
irb(main):001:0> begin
irb(main):002:1* begin
irb(main):003:2* puts 1
irb(main):004:2> next
irb(main):005:2> end
irb(main):006:1> puts 2
irb(main):007:1> end
1
=> nil
Why doesn't this fail on jruby like it does on cruby? Is this a jruby bug?
I filed this as Bug #13064.
I tested your code in a variety of versions of YARV, as well as on the latest versions of JRuby, MRuby, and Rubinius:
YARV 2.2.0 (the build shipping with macOS)
YARV 2.3.1 (the version JRuby claims to be compatible with at the moment)
YARV 2.3.3
YARV 2.4.0-preview3:
YARV 2.4.0-dev (current SVN trunk as of yesterday):
Rubinius 3.69
JRuby 9.1.6.0 (the latest release)
MRuby 1.2.0 (the minimal ISO compliant Ruby implementation written by matz himself)
What is most interesting is that MRuby, JRuby and Rubinius actually agree on the behavior, but differ from YARV. Either YARV or all the other ones are wrong. I cannot say which ones, though.