Skip to content

ensure section is not executed if the function exits via a return in a proc #6099

@suetanvil

Description

@suetanvil

In the following function:

def outer
  puts "open"
  proc{ return 42 }.call
ensure
  puts "close"
end

the ensure block is not executed in this case, as it is with CRuby and JRuby.

Replacing the proc with just return 42 behaves as expected. So does exiting via a block argument, like this:

def inner(&block)
  puts "open"
  return block.call
ensure
  puts "close"
end

def outer
  inner { return 42 }
end

outer()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions