hoshiumiarata · GitHub

It seems that when using return in a block, the function unwinding is not working as expected under certain conditions.
In the following example, the first time f is called without a block, and then it is called recursively with a block that contains a return statement.

def f(&block)
  puts "start f"
  if block == nil
    f { return 1 }
  else
    block.call
  end
  puts "end f"
end
f

The block is defined in the first call, so return should return from the first call of f after calling block.call. However, it continues to the next line and prints "end f".

Output of ruby 3.3.0:

start f
start f
=> 1

Output of mruby (master branch):

start f
start f
end f
 => nil

Read the original on github.com ↗